script check to see if device is mounted
Hi I want to be able to be able to check to see if a device is mounted ie pendrive
if [code to see if drive mounted ] :then ..... also can I use exit status like.. es=$? if [$es = 32 ] then: .... TIA WD PS. is there a set of generic switches for scripting(if yes where can I find) or are they specific to commands |
Re: script check to see if device is mounted
Quote:
if mount | grep <pen-drive's mountpoint> I have no idea what you mean by generic switches. CHeers, Tink |
Thanks for the reply. What I mean by generic switches are the various switches/options I have seen in scripts
like.... if [ -n "$DIR_STACK" ] ; then ..... or ....if [ -z "$1" ] ; then... WD |
Code:
man bash Cheers, Tink |
Hi Warmduvet,
The "[" (square backet) is a link to "/usr/bin/test". You may look at "man test" to see what you are looking for. |
Thanks Os that was easier
$ man bash /conditional expressions just opened the bash man page at the beginning thanks anyway Tink WD |
Try it with a <return> between man bash
and the /CONDITIONAL EXPRESSIONS and note that this is case sensitive. Cheers, Tink |
that worked :)
thanks WD |
Pleasure mate ;}
Cheers, Tink |
Hey Tink, used the...if mount | grep <pen-drive's mountpoint> wich returns true if the drive is mounted. What I wanted to test for was to see if the pendrive was
plugged in, then outputting rude message to self if it isn't :). Is it possible to test to see wether or not a device is attached but not mounted? WD |
Sure, but slightly more complex ... depends a bit
on distro, too If you have hot-plugging enabled and usb-storage and the sg and/or sd_mod modules are loaded you can check for it using fdisk -l | grep \/dev\/sd HIH Cheers, Tink |
lol tried ... fdisk -l | grep \/dev\/sd came back with fdisk command not found.
I know usb-storage is loaded how do I check for other modules ? I think hot-plugging is enabled. When I'm in text mode and plug the drive in it registers immediately.... SCSIdevice sda: 240640 512-byte hdwr sectors (123 MB) sda: write protect is off. |
fdisk (naturally) is something only root should
be allowed to use - therefore it's not in your path, and if it were you'd just get an error that you can't open the device ... In this case ... the smartest way of tackling that may depend on the distro you're using ... :) You could probably add your normal user to the disk group (caution what you do after that, you can then write to raw devices which spells DANGER!!) and run /sbin/fdisk -l You could set-up sudo to allow you exactly that command (safer, but a bit more set-up). Cheers, Tink |
Ill try the sudo way as I am already using that for other commands.
Thanks for the help WD |
No worries, good luck! :)
Cheers, Tink |
All times are GMT -5. The time now is 03:39 AM. |