LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   script check to see if device is mounted (http://www.linuxquestions.org/questions/programming-9/script-check-to-see-if-device-is-mounted-225910/)

Warmduvet 09-02-2004 06:52 PM

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

Tinkster 09-02-2004 07:54 PM

Re: script check to see if device is mounted
 
Quote:

Originally posted by Warmduvet
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

The easiest way to do that would be to
if mount | grep <pen-drive's mountpoint>

I have no idea what you mean by generic switches.



CHeers,
Tink

Warmduvet 09-02-2004 09:37 PM

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

Tinkster 09-02-2004 09:55 PM

Code:

man bash
/CONDITIONAL EXPRESSIONS

Type that and read ;}


Cheers,
Tink

osvaldomarques 09-02-2004 11:55 PM

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.

Warmduvet 09-03-2004 01:09 AM

Thanks Os that was easier


$ man bash /conditional expressions
just opened the bash man page at the beginning

thanks anyway Tink


WD

Tinkster 09-03-2004 01:23 AM

Try it with a <return> between man bash
and the /CONDITIONAL EXPRESSIONS
and note that this is case sensitive.



Cheers,
Tink

Warmduvet 09-03-2004 01:51 AM

that worked :)

thanks

WD

Tinkster 09-03-2004 01:53 AM

Pleasure mate ;}


Cheers,
Tink

Warmduvet 09-03-2004 03:18 PM

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

Tinkster 09-03-2004 04:12 PM

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

Warmduvet 09-03-2004 04:47 PM

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.

Tinkster 09-03-2004 05:08 PM

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

Warmduvet 09-03-2004 05:56 PM

Ill try the sudo way as I am already using that for other commands.

Thanks for the help

WD

Tinkster 09-03-2004 06:17 PM

No worries, good luck! :)


Cheers,
Tink


All times are GMT -5. The time now is 04:04 AM.