Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
as part of a backup system, I use 2 very simple scripts to mount and unmount a harddrive;
To mount;
#!/bin/sh
#/sbin/backup-mount
echo " /dev/sda5 mounted at /mnt/backup" >>/var/log/messages
mount /dev/sda5 /mnt/backup >>/var/log/messages
echo " /dev/sda5 mounted at /mnt/backup"
To unmount;
#!/bin/sh
#/sbin/backup-unmount
sync
echo "/mnt/backup now offline" >>/var/log/messages
umount /dev/sda5 >>/var/log/messages
echo "/mnt/backup now offline"
The problem is that when devices get (often) inserted in a haphazard manner, the drive isn't sda5 anymore, but sometimes sdb5, sdc5, sdd5 etc, and then the script doesn't work anymore.
How can I alter the script so that it picks up sd*5?
This is a problem that udev was developed to solve.
See here: http://www.reactivated.net/writing_udev_rules.html
There are several example rules that you can modify to suit your needs. udev needs to be restarted before your new rule will take effect.
Welcome to LQ!
I read that people who have this kind of problem with booting use a disk identifier so that the GRUB will find it without the sda5 setting. I think that is the
Quote:
UUID
you mentioned. Does mount work with UUID? They would put the UUID in the file /etc/fstab and then also in the GRUB menu, so that it would boot up without the sda5 setting.
Shell scripts can handle input in the form of $1 (for the first parameter passed), etc.
Change the script so that it will take the drive letter from the command-line parameter (if no such parameter is passed, then apply a default value like 'a').
This way you will not have to change the script in the future, but you can still act flexible on a changed drive configuration.
The problem has expanded: several different harddrives (with differing UUIDS etc, of course) will be used, and each of these needs to be mounted to /dev/sda5 when it's connected. How can this be done?
Why not use you original script like a subroutine and pass it the $1 from another(master) script. Then have a different master script for each drive(backup1, backup2, etc). I can see no good reason that you should be limited to /dev/sda5.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.