Posts Tagged shell script

Check USB harddisk mounted or not in Linux

Today, I am checking how to use a script to check if USB hard disk is mounted or not in Linux.

After doing research, I developed the following script to check “mount” status.

1. Create a file chk_mount.sh.
2. chmod 755 chk_mount.sh
3. Add the follow content to “chk_mount.sh”.

if mount | grep sdb1 > /dev/null
then
        echo "sdb1 mounted"
else
        echo "No sdb1"
        mount /dev/sdb1 /backup
fi

If sdb1 is mounted, there is no action will be taken.
If sdb1 is not mounted, /dev/sdb1 will be mounted automatically.

You can put this script in cron job and check  mount status regularly.

VN:F [1.9.18_1163]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.18_1163]
Rating: 0 (from 0 votes)
Total views: 4,824 views

,

No Comments