LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 05-07-2007, 03:01 PM   #1
Soulja1
LQ Newbie
 
Registered: Sep 2003
Location: Ottawa, Canada
Distribution: Suse
Posts: 6

Rep: Reputation: 0
script for checking if a drive is mounted


i was wondering if anyone knows how i can make a script to check if a drive is mounted or not. The reason for the script is i want to automate my tar backs but my backups go to a samba mounted drive. I however am on a notebook and sometimes i am not on the network with the samba share, so i can't have my backup program run during this time.
 
Old 05-07-2007, 03:04 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 39,821

Rep: Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116Reputation: 1116
well just run "mount" and grep for the name of the share you're interested in. you could run that and check the value of $? after it, or just use test to see if the output is nonzero

[ "$(mount | grep sharename") ] && script_to_mount_share
 
Old 05-07-2007, 03:07 PM   #3
kromberg
Member
 
Registered: Feb 2007
Location: Colorado
Distribution: FC6, FC7 x86_64
Posts: 218

Rep: Reputation: 30
Code:
#!/bin/ksh

mounted=`df | grep "/mntpoint"`

if [[ mounted != "" ]] ; then
   tar cfv /mntpoint/blah.tar blah
else
   print "backup drive not mounted."
fi
Replace /mntpoint with the directory where you mounted the backup drive in. Also replace blah.tar and blah with the name of the tarball and the directory you want to backup.

Keith
 
  


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
How to test is a drive is mounted in a shell script? agtlewis Linux - General 7 03-18-2009 09:58 AM
Run script when USB drive is mounted highgeere Linux - Desktop 2 11-13-2006 08:44 AM
Checking and changing DOS attributes on a samba mounted share nkendrick Linux - Software 1 08-24-2006 07:47 PM
script to check if a drive is mounted gazman1 Programming 3 07-10-2006 09:09 AM
Checking if a device is mounted using a script thar Linux - Software 2 02-22-2004 03:17 PM


All times are GMT -5. The time now is 11:50 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
Open Source Consulting | Domain Registration