Friday, January 30, 2009

Script to mount multiple isos.

#!/bin/bash
#===============================================================================
#
# FILE: deand.sh
#
# USAGE: ./deand.sh
#
# DESCRIPTION: To mount partition and then the iso
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Parag Kalra (), paragkalra@gmail.com, www.paragkalra.com
# COMPANY: As of now Persistent System LTD, www.persistentsys.com
# VERSION: 1.0
# CREATED: Thursday 29 January 2009 08:04:14 IST IST
# REVISION: 2
#===============================================================================

#-------------------------------------------------------------------------------
# Creating "/temp" if it doesn't exist
#-------------------------------------------------------------------------------
if [ ! -d /temp ]
then
mkdir /temp
fi

#-------------------------------------------------------------------------------
# Creating /iso if it doesn't exist
#-------------------------------------------------------------------------------
if [ ! -d /iso ]
then
mkdir /iso
fi

echo " "

#-------------------------------------------------------------------------------
# Mounting partition and then the iso
#-------------------------------------------------------------------------------
if ! mount | grep sda1
then
echo -e "Mounting partition\n"
mount /dev/sda1 /temp
else
echo -e "Partition sda1 already mounted. \n"
fi


#=== FUNCTION ================================================================
# NAME: isomount()
# DESCRIPTION: To mount the respective iso
# PARAMETERS: isoname
# RETURNS: nothing
#===============================================================================
function isomount
{
echo -e "You have selected $1 hence mounting $1 iso\n"
mount -o loop /temp/root/linuxcbt-$1/linuxcbt-$1.iso /iso
}
# ---------- end of function isomount ----------

echo -e "Please enter the ISO you want to mount: \n1. rhel4\n2. sendmail\n3. samba\n4. security\n5. rhel5dvd\n6. postfix\n7. qmail"
read iso

case $iso in

rhel4)
isomount rhel4
;;

samba)
isomount samba
;;

security)
isomount security
;;

sendmail)
isomount sendmail
;;

postfix)
isomount postfix
;;

qmail)
isomount qmail
;;

rhel5dvd)
echo -e "You have selected $iso hence trying to mount $iso \n"
if ! mount | grep rhel5iso
then
echo -ec"Mounting $iso \n"
mount -o loop /temp/root/RHEL-5.1-i386-DVD.iso /share/rhel5iso
else
echo -e "$iso already mounted. \n"
fi
;;

esac

# --- end of case ---

Sunday, January 18, 2009

BASH script to copy a remote database !!!

#!/bin/bash
#===============================================================================
#
# FILE: db_sync.sh
#
# USAGE: ./db_sync.sh
#
# DESCRIPTION: To sync the remote database
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: -----
# AUTHOR: Parag Kalra (), paragkalra@gmail.com, www.paragkalra.com
# COMPANY: As of now Persistent System LTD, www.persistentsys.com
# VERSION: 1.0
# CREATED: Sunday 18 January 2009 12:44:49 IST IS
# REVISION: ---
#===============================================================================

#-------------------------------------------------------------------------------
# Storing username, password & logfile in a variable
#-------------------------------------------------------------------------------
myuser=some_user
mypasswd=some_password
mylog=/var/log/projects/db_sync.log


#-------------------------------------------------------------------------------
# Executing a SQL file to create & drop local databases.
#-------------------------------------------------------------------------------
echo "Executing SQL file - `date`" > $mylog
mysql --verbose --user=$myuser --password=$mypasswd --host=localhost < /data/projects/mysql/alter_dbs.sql #---------------------------- #Dumping the remote database on the local setup #---------------------------- echo "Dumping remote mysql databases- `date`" >> $mylog
mysqldump --verbose --user=$myuser --password=$mypasswd --host=www.paragkalra.com some_database > /data/databases/pkc_db_`date +%F`.sql


#-------------------------------------------------------------------------------
# Importing the database
#-------------------------------------------------------------------------------
echo "Importing the database - `date`" >> $mylog
mysql --verbose --user=$myuser --password=$mypasswd some_database < /data/databases/pkc_db_`date +%F`.sql
echo "Export - Import of database complete - `date`" >> $mylog