Friday, 14 August 2015

BASH SCRIPT AND CRON FOR mysqldump PROCESS(LINUX):

This script will help to take mysql dump particularly when you want to exclude few db in server.


* kindly update the required database list on the file: db.list

With password:

#!/bin/bash
#script will use for when you take db backup for selective range of db's
for i in `cat db.list`
do mysqldump --user="username" --password="password" $i > $i.sql
if [ $? -ne 0 ]
then
echo $i Failed >> db_filed.txt
else
echo $i Success >> db_success.txt
fi
done


Without password:

#!/bin/bash
#script will use for when you take db backup for selective range of db's
for i in `cat db.list`
do mysqldump $i > $i.sql
if [ $? -ne 0 ]
then
echo $i Failed >> db_filed.txt
else
echo $i Success >> db_success.txt
fi
done


Add to cron:

# vi mysql_dump_cron.sh
#!/bin/bash
#script will use for when you take db backup for selective range of db's
BACKUP=DB_BACKUP_`date +%Y-%m-%d-%H:%M`
mkdir -p /path/to/BACKUP
for i in `cat /path/to/db.list`
do mysqldump $i > /path/to/BACKUP/$i.sql
if [ $? -ne 0 ]
then
echo $i Failed >> /path/to/BACKUP/db_filed.txt
else
echo $i Success >> /path/to/BACKUP/db_success.txt
fi
done


Daily cron:

0 0 * * * /path/to/the/script/mysql_dump_cron.sh > /dev/null 2>&1

Wednesday, 12 August 2015

How To Find My Public IP Address From Command Line:

To Find My Public IP Address From Command Line:


# host myip.opendns.com resolver1.opendns.com | grep ^myip | awk '{print $4}'

(or)

# dig myip.opendns.com @resolver1.opendns.com +short

(or)

# dig TXT o-o.myaddr.l.google.com @ns1.google.com +short

:-) !