LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Check to see if a drive is mounted (https://www.linuxquestions.org/questions/linux-newbie-8/check-to-see-if-a-drive-is-mounted-380749/)

joshnya 11-07-2005 08:05 AM

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

Dtsazza 11-07-2005 08:24 AM

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.

joshnya 11-07-2005 08:56 AM

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.


All times are GMT -5. The time now is 02:12 PM.