LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-02-2004, 06:52 PM   #1
Warmduvet
Member
 
Registered: Jun 2004
Location: New Zealand
Posts: 60

Rep: Reputation: 15
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

Last edited by Warmduvet; 09-02-2004 at 07:00 PM.
 
Old 09-02-2004, 07:54 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,978
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
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
 
Old 09-02-2004, 09:37 PM   #3
Warmduvet
Member
 
Registered: Jun 2004
Location: New Zealand
Posts: 60

Original Poster
Rep: Reputation: 15
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

Last edited by Warmduvet; 09-02-2004 at 09:46 PM.
 
Old 09-02-2004, 09:55 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,978
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Code:
man bash
/CONDITIONAL EXPRESSIONS
Type that and read ;}


Cheers,
Tink
 
Old 09-02-2004, 11:55 PM   #5
osvaldomarques
Member
 
Registered: Jul 2004
Location: Rio de Janeiro - Brazil
Distribution: Conectiva 10 - Conectiva 8 - Slackware 9 - starting with LFS
Posts: 519

Rep: Reputation: 34
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.
 
Old 09-03-2004, 01:09 AM   #6
Warmduvet
Member
 
Registered: Jun 2004
Location: New Zealand
Posts: 60

Original Poster
Rep: Reputation: 15
Thanks Os that was easier


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

thanks anyway Tink


WD
 
Old 09-03-2004, 01:23 AM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,978
Blog Entries: 11

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



Cheers,
Tink
 
Old 09-03-2004, 01:51 AM   #8
Warmduvet
Member
 
Registered: Jun 2004
Location: New Zealand
Posts: 60

Original Poster
Rep: Reputation: 15
that worked

thanks

WD
 
Old 09-03-2004, 01:53 AM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,978
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Pleasure mate ;}


Cheers,
Tink
 
Old 09-03-2004, 03:18 PM   #10
Warmduvet
Member
 
Registered: Jun 2004
Location: New Zealand
Posts: 60

Original Poster
Rep: Reputation: 15
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

Last edited by Warmduvet; 09-03-2004 at 03:57 PM.
 
Old 09-03-2004, 04:12 PM   #11
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,978
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
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
 
Old 09-03-2004, 04:47 PM   #12
Warmduvet
Member
 
Registered: Jun 2004
Location: New Zealand
Posts: 60

Original Poster
Rep: Reputation: 15
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.
 
Old 09-03-2004, 05:08 PM   #13
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,978
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
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
 
Old 09-03-2004, 05:56 PM   #14
Warmduvet
Member
 
Registered: Jun 2004
Location: New Zealand
Posts: 60

Original Poster
Rep: Reputation: 15
Ill try the sudo way as I am already using that for other commands.

Thanks for the help

WD
 
Old 09-03-2004, 06:17 PM   #15
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,978
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
No worries, good luck! :)


Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash-Check If FS is Already Mounted On Directory fortezza Programming 15 04-27-2013 07:06 PM
Check to see if a drive is mounted joshnya Linux - Newbie 2 11-07-2005 08:56 AM
Checking if a device is mounted using a script thar Linux - Software 2 02-22-2004 03:17 PM
SCRIPT: check if auto-mount mount-points are still mounted markus1982 Linux - Software 0 05-25-2003 05:48 AM
Check if it IS mounted sourceman Linux - General 11 02-27-2002 08:31 AM


All times are GMT -5. The time now is 10:59 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration