| View previous topic :: View next topic |
| Author |
Message |
danomac l33t


Joined: 06 Nov 2004 Posts: 810 Location: Vancouver, BC
|
Posted: Tue Mar 13, 2012 6:15 pm Post subject: Check if CIFS share is mounted? |
|
|
I've been writing a backup script. I've got it mostly working/hacked/cobbled together with the exception of one thing: I need to ensure a CIFS mountpoint is mounted before copying files to it. (The CIFS share is backed up to external medium on a daily basis.)
I discovered the mountpoint command, but it doesn't seem to work on network shares:
| Code: |
# mountpoint -q /mnt/server && echo "Mounted" || echo "Not mounted"
Not mounted
|
The network share is mounted, and I can access it. If I mount /boot and run the above it works?
Or is mountpoint only used for actual physical devices (i.e. not network shares?)
I'd rather not test to see if a file exists, as it's not very elegant and can be screwed by someone else deleting the file.
Suggestions?
Last edited by danomac on Tue Mar 13, 2012 6:38 pm; edited 1 time in total |
|
| Back to top |
|
 |
disi Veteran


Joined: 28 Nov 2003 Posts: 1351 Location: Out There ...
|
Posted: Tue Mar 13, 2012 6:23 pm Post subject: |
|
|
And if you write the file every time? Too much overhead?
| Code: | | % echo 'test' > /mnt/auto/data/test && test -e /mnt/auto/data/test && echo lueppt |
I actual get this:
| Code: | % mountpoint -q /mnt/auto/data | echo $?
1 |
//edit:
well automount
| Code: | % ls /mnt/auto/data
backup expunged games images
% mountpoint -q /mnt/auto/data | echo $?
0 |
_________________ Gentoo on Uptime Project - Larry is a cow |
|
| Back to top |
|
 |
nomilieu n00b


Joined: 22 Nov 2011 Posts: 24
|
Posted: Tue Mar 13, 2012 6:31 pm Post subject: |
|
|
Try df.
It should list those shares if they are mounted, and you could just check to see that they appear in the output. |
|
| Back to top |
|
 |
aidanjt Veteran


Joined: 20 Feb 2005 Posts: 1101 Location: Rep. of Ireland
|
|
| Back to top |
|
 |
danomac l33t


Joined: 06 Nov 2004 Posts: 810 Location: Vancouver, BC
|
Posted: Tue Mar 13, 2012 6:34 pm Post subject: |
|
|
If I write a file and the system is not mounted, it writes to the local filesystem.
I need to make sure the mountpoint is mounted so it goes to the server's filesystem.
Edit: Thanks aidanjt... I actually read that thread but missed that post, thanks to my #$%&* mouse's screwy scrollwheel. |
|
| Back to top |
|
 |
danomac l33t


Joined: 06 Nov 2004 Posts: 810 Location: Vancouver, BC
|
Posted: Wed Mar 14, 2012 5:43 pm Post subject: |
|
|
I used the thread from aidanjt and modified it until it worked.
This works on remote shares as well as local mounts:
| Code: |
#!/bin/sh
function ismounted() {
if [ `stat -fc%d "$1"` != `stat -fc%d "$1/.."` ]; then
return 0
else
return 1
fi
}
if ismounted $1; then
echo "It is mounted, sir."
else
echo "It is NOT mounted, sir."
fi
|
|
|
| Back to top |
|
 |
BoneKracker Veteran


Joined: 14 Mar 2006 Posts: 1488 Location: U.S.A.
|
Posted: Thu Mar 15, 2012 1:10 pm Post subject: |
|
|
Can you just grep /etc/mtab or /proc/mounts?
Or, with cifs, can you do a fake mount ('mount -f') and check the error code? _________________ Oldthinkers unbellyfeel INGSOC.
-- Headline of a document on Winston Smith's terminal in his cubicle at the Ministry of Truth, seen briefly in the background in one scene of the movie rendition of Nineteen Eighty-Four. |
|
| Back to top |
|
 |
nomilieu n00b


Joined: 22 Nov 2011 Posts: 24
|
Posted: Thu Mar 15, 2012 1:33 pm Post subject: |
|
|
The first two work, but I'm not sure about the fake mount option.
There are likely a zillion ways to do it though. It's just whatever pops into your head first. |
|
| Back to top |
|
 |
|