LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Help writing script file to mount / mount hard drive (https://www.linuxquestions.org/questions/linux-general-1/help-writing-script-file-to-mount-mount-hard-drive-457566/)

Rustylinux 06-23-2006 09:17 AM

Help writing script file to mount / mount hard drive
 
Hey,

Just need some help writing a script to mount / unmount a hot swap hard drive that I have in my system. I recently put in a hot swap drawer for one of my sata drives and need to figure out how to write a script so it mounts / unmounts it. Any help would be greatly appricated.


Thanks

acid_kewpie 06-23-2006 09:27 AM

what do you need a script for? what's wrong with just using mount and umount?

actually... you might be interested in autofs, where if a drive is not used for 60 seconds or something, it is unmounted automatically. also mounted on access, not on boot... might be what you're really after.

Rustylinux 06-23-2006 10:52 AM

The reason why I want to write a script for it is for backups. The drive was put into the system so it can do backups when i'm out on the weekends. I was planning on writing a script and then just getting scheduled tasks to run it at a certian time to mount the drive before the backup occurs and to unmount it after it is finished.

acid_kewpie 06-23-2006 11:01 AM

well that's just a bunch of standard commands in a file, there's nothign particuarly interesting about the way you would umount it here.

Rustylinux 06-27-2006 09:21 AM

Thats what I would like some help on. Would it just be a simple mount and unmount in the script file?

ethics 06-27-2006 09:31 AM

you wouldn't need a script, as all it would be doing is giving the mount/umount commands to the shell, which you can type anyway.

Personally i'd just add a line to /etc/fstab with the noauto option, check the file for a good idea of what a line looks like, pretty self expanatary. Using no auto means its not mounted at boot, whilst that would be good if its attached when the box is booted, it can take a few extra seconds/mins for it to crap out on the mount and carry on booting.

Then you could just type mount <mount_point> or umount <mount_point> as the mount command searches /etc/fstab (and mtab but i never use that) for a line with that mount point, and gets the options off of there.

You could use a script if you wanted a cron job whereby the mount/umount commands are executed on a timer

binary_y2k2 06-27-2006 09:34 AM

you could just put at the start of your backup script:
Code:

/path/to/mount/script mount
and at the end:
Code:

/path/to/mount/script unmount
and make a mount script like:
Code:

if [ "$1" = "mount" ]; then
mount /dev/<device> /mount/point -t ext3 -o rw
exit 0
elif [ "$1" = "unmount" ]; then
umount /mount/point
exit 0
else
exit 0
fi



All times are GMT -5. The time now is 08:45 PM.