LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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

Reply
 
LinkBack Search this Thread
Old 11-07-2005, 08:05 AM   #1
joshnya
Member
 
Registered: Feb 2003
Location: Boston, MA
Distribution: RedHat 9
Posts: 39

Rep: Reputation: 15
Check to see if a drive is mounted


Hello--

Is there a way (command or script) that the system can automatically check to see if a drive is mounted ?

I have an external USB drive that functions as a back-up drive where everything gets copied over to once per day via a "CP" command that is fired off by cronjobs.

Here is my cronjobs line:

45 02 * * 1-5 cp -ru --reply=y /mnt/share /media/usbdisk

Is there a way the system can verify the USB drive is mounted prior to running the "CP" job and if not, cancel the copy process?

Thanks for the advice.

Joshua
 
Old 11-07-2005, 08:24 AM   #2
Dtsazza
Member
 
Registered: Oct 2005
Location: Oxford, UK
Distribution: Debian Etch (w/ dual-boot XP for gaming)
Posts: 282

Rep: Reputation: 30
The mount command with no arguments will show all filesystems that are mounted. So, you could issue mount on its own, grep the output for say, "/media/usbdisk", and then count the number of lines in the output. 0 means it's not mounted, 1 means it is.

As a little extra, the && operator between commands actually means "return the result of the first command ANDed with the result from the second command"; but since its lazy, what it means in practice (especially if you discard its return) is that it will execute the second command only if the first one returned successfully. You could thus have your cron job running "check_mounted && cp...", which would bypass the copying if the check_mounted command didn't return successfully.

Last edited by Dtsazza; 11-07-2005 at 08:28 AM.
 
Old 11-07-2005, 08:56 AM   #3
joshnya
Member
 
Registered: Feb 2003
Location: Boston, MA
Distribution: RedHat 9
Posts: 39

Original Poster
Rep: Reputation: 15
Thanks for the response.

Can you please expand on the check_mounted command? I'm assuming it's a script.


If so, and I understand you, the check_mounted file should look like this....
__________________________
mount | grep /media/usbdisk
__________________________

Yes or No?


How do I make the check_mounted file a function or utility file that executes?

Thanks again.

P.S. Again, I'm very new at this (but Im learning) so I appoligize if I'm not following simple suggestions.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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
drive mounted noobtesting Mandriva 3 10-05-2004 07:51 PM
script check to see if device is mounted Warmduvet Programming 14 09-03-2004 06:17 PM
Boot disk; check. CD in drive; check. Doesn't work; check. Hal DamnSmallLinux 7 02-04-2004 02:10 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 08:32 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