Tuesday, January 31, 2017

How to Upload Files on Google Drive from Linux Console

Follow below steps to use google drive from linux termial

Download google drive version for linux
wget https://docs.google.com/uc?id=0B3X9GlR6EmbnWksyTEtCM0VfaFE&export=download

yum install wget
wget https://docs.google.com/uc?id=0B3X9GlR6EmbnWksyTEtCM0VfaFE&export=download

You will see a file like above. Rename it with gdrive
mv uc\?id\=0B3X9GlR6EmbnWksyTEtCM0VfaFE gdrive

chmod +x gdrive

install gdrive /usr/local/bin/gdrive

Run below command to check

[root@bhagwat home]# gdrive list
Authentication needed
Go to the following url in your browser:
https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=367116221053-7n0vf5akejinrecpdoe99eg.apps.googleusercontent.com&redirect_uri=urn%3Aiet%3Awg%3oau%3A2.0%3Asponse_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=state

Enter verification code:

Just copy the above url & paster in your browser. Copy verification code here & you are done. Now you can use your google drive directly from terminal.

Upload any file with below command
[root@bhagwat home]# gdrive upload my_photos.zip

Use gdrive help command for more options
[root@bhagwat home]# gdrive help

Wednesday, January 25, 2017

Find files with specific extensions in current directory

Find files with specific extensions in current directory (you can add multiple extensions as per syntax

find . -type f \( -name "*.sh" -o -name "*.txt" \)
find /home/bhsingh/ -type f \( -name "*.png" -o -name "*.jpg" -o -name "*.deb" -o -name ".pdf" \)

Find file & redirec the result to a file

find /home/www/html -type f \( -name "*.php"\) -print0 | xargs -0 stat --format '%Z :%z %n' | sort -nr > /home/bhsingh/php_files.txt
find / -type f -print0 | xargs -0 stat --format '%Z :%z %n' | sort -nr > /root/all_files.txt

Tuesday, January 24, 2017

Not able to install googleads-php-lib on Centos

[bhagwat@server1 googleads-php-lib-25.1.0]$ php composer.phar require googleads/googleads-php-lib

Using version ^25.1 for googleads/googleads-php-lib
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- The requested package googleads/googleads-php-lib No version set (parsed as 1.0.0) is satisfiable by googleads/googleads-php-lib[No version set (parsed as 1.0.0)] but these conflict with your requirements or minimum-stability.


Solution

Issue was resolved after upgrading composer with below command

php composer.phar update

(Composer seems not to be able to detect the version of the library and thus cannot install the library of v25.1 as requested.)

Test hard disk performace on Linux Server

Performance testing was done on /dev/sda drive with cache enable & disable mode of hard drive

cache enable/disable syntax is below
hdparm -W(value) /dec/sda

Value 0 means cache disable
Value 1 means cache enable

One gigabyte was written for the test, first with the cache activated (hdparm -W1 /dev/sda):

root@bhagwat~# dd if=/dev/zero of=/root/testfile bs=1G count=1 oflag=direct
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 32.474 s, 33.1 MB/s
root@bhagwat~#


Then, with the cache deactivated (hdparm -W0 /dev/sda):

root@bhagwat~# dd if=/dev/zero of=/root/testfile bs=1G count=1 oflag=direct   
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 123.37 s, 8.7 MB/s

Friday, January 20, 2017

Cron need to run on every Monday of the Month

Need to add a cron entry which should execute on every Monday of month.
Or
You can use it for any other day (changing "Mon" with other days")


00 04 1-7 * * [ "$(date '+\%a')" == "Mon" ] && perl /home/bhagwat/cron/my_script.pl
00 04 8-15 * * [ "$(date '+\%a')" == "Mon" ] && perl /home/bhagwat/cron/my_script.pl
00 04 24-31 * * [ "$(date '+\%a')" == "Mon" ] && perl /home/bhagwat/cron/my_script.pl

Thursday, January 19, 2017

Switch one user with other user without password

Switch one user with other user without password (sudoers entry)

You need to allow one user to run switch user & work as other user

Add below entry in sudoers file

user1 ALL= NOPASSWD: /bin/su user2


Now user1 can switch as user2 with below command

sudo su user2

Password Protect file in vim text editor

Password protecting file in vim text editor
add +X before any file name & it will prompt you to enter a password

Example
vim +X filename

Now next time it will ask for the password while opening the file

If you don't want the password you can simply remove the same with below stpes
Open you file & press Esc

:set key=
then, save the file

Wednesday, January 18, 2017

Find top 10 directroy by size in linux

Find top 10 directroy by size in linux



Simply run below command to display the results

du -hs * | sort -rh | head -10


In few systems the "h" extenion is not working. They can use below command instead

du -s * | sort -rn | awk '{print int($1 / 1024) "M\t"$2}' | head -10

If data is in GBs then there is a little modification in command

du -s * | sort -rn | awk '{print int($1/1024/1024 ) "G\t"$2}' | head -10

Wednesday, January 11, 2017

How to upgrade from RHEL 6 to RHEL 7 ?

All server editions (except x86) of Red Hat Enterprise Linux 6 can be upgraded with this procedure.
Upgrades of RHEL Workstation and Desktop systems are not supported.
Upgrades for the POWER architecture is supported.

Upgrade from 32-bit architecture is not supported.

Please follow below link for complete details on how to upgrade
https://access.redhat.com/solutions/637583

Tuesday, January 10, 2017

Dropbox Error - zipimport.ZipImportError: not a Zip file: '/usr/libexec/dropbox/library.zip'

Below error coming while starting dropbox application in linux
[bhagwat@bhagwat ~]$ dropbox
Traceback (most recent call last):
  File "<string>", line 5, in <module>
zipimport.ZipImportError: not a Zip file: '/usr/libexec/dropbox/library.zip'

Solution

Open file /etc/prelink.conf and added the line
-b *dropbox*

then

yum reinstall dropbox

After login now it seems that now all work well!!


2nd Solution
To fix the error add the following line to /etc/prelink.conf

# Dropbox fix
-b /usr/libexec/dropbox

Friday, January 6, 2017

BHIM App Information/Details (Common Problems)

With almost 3 million downloads under a week, the app is topping all the charts.

Some of the issues you may encounter with BHIM app & how to solve them.

Device Binding Failed Error or Activation Error
- This error occurs if you have a dual sim phone. To fix this error put the sim card which has the number connected to your bank account into sim slot 1.
With dual sim phones it's a common problem

- if you are trying the app on a phone without SIM card or in airplane mode, then the app won't work. So make sure you have a functioning mobile connection with the number that is tied to your bank accounts.

- You must be also aware that there is a cap on the amount you can transfer. There is a limit of Rs. 10,000 per transaction. Additionally, there is a cap of Rs. 20,000 per day.

- If you didn't receive OTP for a transaction, it must be mostly because of the high loads on the servers. Of course using the app at non-peak hours helps.

- If you got an error saying ' Declined Transaction', then closing and reopening the app will fix it in most cases. However, make sure there is free RAM by closing the other apps running in the background.

Monday, January 2, 2017

Common Mysql Problems & Solutions - Part -1

Here are few common Mysql Replication Errors & their solutions

Problem - 1   

Last_Errno: 1594
Relay log read failure: Could not parse relay log event entry. The possible reasons are: the master's binary log is corrupted (you can check this by running 'mysqlbinlog' on the binary log), the slave's relay log is corrupted (you can check this by running 'mysqlbinlog' on the relay log), a network problem, or a bug in the master's or slave's MySQL code. If you want to check the master's binary log or slave's relay log, you will be able to know their names by issuing 'SHOW SLAVE STATUS' on this slave.

Solution

Run Show slave status & Check these 2 positions
Relay_Master_Log_File: db1-bin.002183
Exec_Master_Log_Pos: 9866809

Stop Slave & Reset the same & provide the position you have noted earlier
mysql> stop slave;
mysql> reset slave;
mysql> change master to master_log_file='db1-bin.002183', master_log_pos=9866809;
mysql> start slave;

It's done now. Let the slave recover it's data with Master

#####################################

PROBLEM - 2

ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository




This error comes when you are creating new Mysql slave & just started the replication with Master

Solition:

Reset slave;
Stop Mysql
Delete mysqld-relay-bin.index in Mysql folder
Start Mysql
Run Change Master to Master command
Start Slave;


#################################

PROBLEM - 3

Last_SQL_Errno: 1305
Last_SQL_Error: Error 'FUNCTION DB.SPLIT_STR does not exist' on query. Default database: 'DB'. Query: 'insert into tablename(folderid, subuid, company, title, summary, descr, keyskills, job_type, minsal, maxsal, minsal_channel,

Solution -
It is related with functions as the above function is not available at slave server
 
Take backup of functions of DB from destination server
mysqldump -u root -p --routines --no-create-info --no-data --no-create-db --skip-opt  DBName > /home/bhagwat/functions.sql

Restore with below command on Slave
mysql --defaults-file=/root/.my.cnf.root DBNAME < /home/bhsingh/functions.sql


##############################

Problem - 4

ERROR 1235 (42000) at line 21: This version of MySQL doesn't yet support 'multiple triggers with the same action time and event for one table'

Solution -
Add --skip-triggers in command & take backup of functions

mysqldump --defaults-file=/root/.my.cnf.root --routines --no-create-info --no-data --no-create-db --skip-opt --skip-triggers bazooka > /home/bhsingh/bazooka1.sql

##############################

Problem - 5

Last_SQL_Error: Error 'Out of resources when opening file


Solution:

Increase Open files limit on server to fix this  issue

Check current limit with below command
[root@server ~]# mysql -u root -p -e 'show variables;' | grep open
have_openssl    DISABLED
innodb_open_files    300
open_files_limit    8000
table_open_cache    2048


Increase the same with below command

[root@server ~]# cat /etc/security/limits.conf |grep mysql
mysql         soft      nofile     12000
mysql         hard      nofile     16000

For Immediate effect change in below file
 vim /etc/security/limits.d/90-nproc.conf
*          soft    nproc     1024
mysql      soft    nofile    12000
mysql      hard    nproc     16000
root       soft    nproc     unlimited

##########################

Will share the next Part of this series in few days

OPTIMIZE THE USE OF RAM for BETTER Performance on High Load Linux Server

Swapiness which is a kernel module that defines when linux has to start to write in the SWAP (an allocated space in the disk) to relieve the RAM.
It may seem obvious that with access times in milliseconds for Hard Disk and in nanoseconds for RAM, it is better to write in the RAM.

Swap Values are defined below   

vm.swappiness = 0 : Swapping will be activated urgently only to avoid out of memory condition.
vm.swappiness = 60 : This is the default value and means that from 40% of Ram occupancy, the kernel writes to the swap.
vm.swappiness = 10 : This what is recommended to improve performance.
vm.swappiness = 100 : The kernel will swap aggressively.

To see your swappiness setting :

cat /proc/sys/vm/swappiness
60
Let’s consider that we have a server having 156G of RAM. fixing the swappiness to 5 is enough since kernel will use swap only when the free RAM space is less or equal to 7.8G.

As root set the swappiness value:

echo 5 > /proc/sys/vm/swappiness

or alternatively, run:

sysctl -w vm.swappiness=5

Verify your changes:

cat /proc/sys/vm/swappiness
5

or:

sysctl vm.swappiness
vm.swappiness = 5

To change this value permanently edit /etc/sysctl.conf and modify (or add if not exist):

vm.swappiness = 5
apply modification:

sysctl -p
swappoff -a && swapon -a