--------------------------------------------------
From: "Raj Mathur (??? ?????)" raju(a)linux-delhi.org
On Monday 22 Nov 2010, Kshitiz wrote:
I use rsync to copy my incremental data to an
external harddisk every
5 minutes using cron. However, if the external harddisk, connected
to the USB port is disconnected, the root partition fills up. I need
your help to create a proper script that does the following:
Before running the rsync copying script, I want to
a) Add some statement that would check if the external harddisk
is attached and mounted. b) If not, it should be mounted before the
copying script is run to copy only to this external disk. c) If it
is not mounted, mount should be attempted, and if it does not mount,
rsync copying command should not be executed.
Assuming your USB device is /dev/hdb1 and it gets mounted on
/media/hdb1, you can try the following:
1. Add an entry in /etc/fstab:
/dev/hdb1 /media/hdb1 auto user 0 0
2. Make an rsync script of the form:
if ! mount | fgrep /dev/hdb1 | fgrep /media/hdb1 > /dev/null
then
mount /dev/hdb1
fi
if mount | fgrep /dev/hdb1 | fgrep /media/hdb1 > /dev/null
then
rsync...
else
echo "USB device not mounted, aborting" >&2
exit 1
fi
Dear Raj & rest of my linuxer friends
Thank you for your efforts and help. I am pasting my code which gives me syntax error
unexpected end on line 17. Need help with why and correction? Am missing something and
cant figure out what?
Urgent help will be really really really appreciated.
-------------
if ! mount -t ntfs | grep /dev/sdc1 | grep /backup > /dev/null
then
mount /dev/sdc1
fi
if mount -t ntfs | grep /dev/sdc1 | grep /backup > /dev/null
then
#is a previous rsync process still running?
ps -ef | grep 'rsync' | grep -v 'grep rsync'| grep -v
'rsync.sh'> /dev/null
if [ $? -eq 1 ]; then #rsync isn't running - let's launch it now
rsync -avz -e --delete /home/ /backup
else
echo "rsync is still running ...please wait and try again later"
fi
fi
--------------
Regards and thanks in advance.
Kshitiz