-------------------------------------------------- From: "Binand Sethumadhavan" binand@gmail.com Sent: Monday, November 22, 2010 9:19 AM To: "GNU/Linux Users Group, Mumbai, India" linuxers@mm.ilug-bom.org.in Subject: Re: [ILUG-BOM] running script only if USB is mounted
2010/11/22 Kshitiz kshitij_kotak@hotmail.com:
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.
All mounted filesystems have an entry in /proc/mounts. Your script can take advantage of this.
if ! grep -q /backup /proc/mounts; then if ! mount -t ext3 /dev/sdb1 /backup; then exit 1; # Mount failed, bail out fi fi
# Regular stuff here
Thank you Binand Reg Kshitiz