Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Check if CIFS share is mounted?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Off the Wall
View previous topic :: View next topic  
Author Message
danomac
l33t
l33t


Joined: 06 Nov 2004
Posts: 810
Location: Vancouver, BC

PostPosted: Tue Mar 13, 2012 6:15 pm    Post subject: Check if CIFS share is mounted? Reply with quote

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
View user's profile Send private message
disi
Veteran
Veteran


Joined: 28 Nov 2003
Posts: 1351
Location: Out There ...

PostPosted: Tue Mar 13, 2012 6:23 pm    Post subject: Reply with quote

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
View user's profile Send private message
nomilieu
n00b
n00b


Joined: 22 Nov 2011
Posts: 24

PostPosted: Tue Mar 13, 2012 6:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
aidanjt
Veteran
Veteran


Joined: 20 Feb 2005
Posts: 1101
Location: Rep. of Ireland

PostPosted: Tue Mar 13, 2012 6:32 pm    Post subject: Reply with quote

Answer #2 seems useful: http://stackoverflow.com/questions/479226/how-to-test-if-a-given-path-is-a-mount-point
_________________
juniper wrote:
you experience political reality dilation when travelling at american political speeds. it's in einstein's formulas. it's not their fault.
Back to top
View user's profile Send private message
danomac
l33t
l33t


Joined: 06 Nov 2004
Posts: 810
Location: Vancouver, BC

PostPosted: Tue Mar 13, 2012 6:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
danomac
l33t
l33t


Joined: 06 Nov 2004
Posts: 810
Location: Vancouver, BC

PostPosted: Wed Mar 14, 2012 5:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
BoneKracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1488
Location: U.S.A.

PostPosted: Thu Mar 15, 2012 1:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
nomilieu
n00b
n00b


Joined: 22 Nov 2011
Posts: 24

PostPosted: Thu Mar 15, 2012 1:33 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Off the Wall All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum