shell script

Mysql backup script

To backup mysql on a daily/hourly basis with time stamp and compress it after backup also it will remove the files older than x days.

#!/bin/bash
# Arun N S
# variables
DATE="$(date +"%d-%m-%Y")"
TIME="$(date +"%d-%m-%Y-%H%M")"
USER=username
PASSWORD=password
DATABASE=dbname


# Directories and dump
/bin/mkdir -p /backup/Mysql/$DATE
/usr/bin/mysqldump -l -F -u $USER --password=$PASSWORD $DATABASE > /backup/Mysql/$DATE/backup_$TIME.sql


# Compressing
/usr/bin/bzip2 /backup/Mysql/*/*.sql


#Removing files older than x days eg: 90 days
for i in `/usr/bin/find /backup/Mysql/ -maxdepth 1 -type d -mtime +90 -print`; do
/bin/echo -e "Deleting old directories $i"; /bin/rm -rf $i; done

Be the first to comment - What do you think?  Posted by Arun N S - January 5, 2010 at 15:22

Categories: Linux, Mysql, shell script   Tags: , , , ,

sed tips

Remove trailing space from a file using sed

$cat | sed 's/[ \t]*$//' >

Be the first to comment - What do you think?  Posted by Arun N S - January 1, 2010 at 20:18

Categories: Linux, shell script   Tags:

Find Tips

Copy/Move files with find

find <path> -name "filename" -exec cp -prf {} /destination/{} \;
find /var/log/ -name "m*" -exec cp -prf {} /tmp/message/{} \;

This will create the same directory structure under /tmp/message, incase you want all subdirectory files under /tmp/message/ remove the {} .

Remove files older than certain days (using find/mtime)
find -name "" -mtime +N -exec rm -r {} \;

Eg : find /var/log/ -name "*.log" -mtime +5 -exec rm -r {} \;
This will remove the *.log files older than 5 days in directory /var/log/

Find with file type

directories : find / -type d -print0
files: find / -type f -print0

Be the first to comment - What do you think?  Posted by Arun N S - at 20:17

Categories: Linux, shell script   Tags:

script to convert openssh keys to tectia and tectia to openssh


#!/bin/bash
# Arun N S
menu="
Make your choice:
1. Openssh key to Tectia format
2. Tectia key to Openssh format
3. Exit"
while :
do
printf "%s\n: " "$menu"
read choice
case $choice in
"1") echo "Converting Openssh key to Tectia format"
echo "Enter key Path(full path):"
while read INPUT
do
ssh-keygen -e -f ${INPUT} > ${INPUT}.tectia
echo "OpenSSH format key is saved as: ${INPUT}.tectia"
exit 0
done
break;;
"2") echo "Converting Tectia key to Openssh format";
echo "Enter File Path(full path):"
while read INPUT
do
ssh-keygen -i -f ${INPUT} > ${INPUT}.openssh
echo "OpenSSH format key is saved as: ${INPUT}.openssh"
exit 0
done
break;;
"3") echo "3. Exit"
echo " Good Bye"
break;;
*) echo "Wrong Choice"
;;
esac
done

./arun

Be the first to comment - What do you think?  Posted by arun - December 9, 2009 at 20:24

Categories: Linux, shell script   Tags: