"mount" gives up too quick

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
I have this script, here is the relevant part:
/usr/admsnap/admsnap activate -s $SESSION -o /dev/$DEV
mount -t ext3 /dev/${DEV}1 /export/snaps/$SNAP -o ro,acl,user_xattr

but the mount command fails because it says the device does not exist. That admsnap command creates a snapshot on our SAN and attaches it to /dev/$DEV. I think what is happening is the SAN does not have enough time to create the snapshot before the script goes on to mount it.

If I put in several mount commands, ie:
/usr/admsnap/admsnap activate -s $SESSION -o /dev/$DEV
mount -t ext3 /dev/${DEV}1 /export/snaps/$SNAP -o ro,acl,user_xattr
mount -t ext3 /dev/${DEV}1 /export/snaps/$SNAP -o ro,acl,user_xattr
mount -t ext3 /dev/${DEV}1 /export/snaps/$SNAP -o ro,acl,user_xattr
mount -t ext3 /dev/${DEV}1 /export/snaps/$SNAP -o ro,acl,user_xattr
mount -t ext3 /dev/${DEV}1 /export/snaps/$SNAP -o ro,acl,user_xattr
mount -t ext3 /dev/${DEV}1 /export/snaps/$SNAP -o ro,acl,user_xattr

then eventually one of the mounts will take. Is there any way I can just tell mount to wait a bit longer to see if /dev/$DEV becomes available?
 

Smilin

Diamond Member
Mar 4, 2002
7,357
0
0
put a ping to nowhere with your desired milliseconds in wait time just before the mount?

For what it's worth. I'm a Windows guy. I have no idea :p


windows syntax for a 5 sec wait...
ping 192.168.254.254 -w 5000
 

drag

Elite Member
Jul 4, 2002
8,708
0
0
'lazy' umount is what you use when you can't get the system to unmount something because it's in use.

What it does is it just umounts it for any new proccess while still allowing the running proccesses to access the files they are using.

Note that Linux does do file locking like Windows does, were it won't let you delete files and such that are in use.. the difference is that Linux does the locking at the inode (or link pointer or whatnot) level rather then the file name level. So the VFS can do things like make it seem that files have been deleted while they are actually being accessed. (you can find these files in /proc/ under the various PID named directories. It is handy for rescuing recently deleted files)


With this you just want to stick a 'sleep' command.

sleep 1
will make it pause for one second.

sleep 10
will make it pause for 10.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: Smilin
put a ping to nowhere with your desired milliseconds in wait time just before the mount?

For what it's worth. I'm a Windows guy. I have no idea :p


windows syntax for a 5 sec wait...
ping 192.168.254.254 -w 5000

That's not a bad idea. :p

It's like an active sleep...
 

cmv

Diamond Member
Oct 10, 1999
3,490
0
76
You could also toss a "sleep x" in there were x is in seconds in the case you don't want it to try to keep mounting it forever.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Originally posted by: Nothinman
Something like this would probably be better

Ah, me like. I'm not much of a Bash programmer, so I googled around to figure out what the '-f' meant (the 'until' was obvious) and I came across this guide. This is going to help me in a few other places, too.

Thanks, Noth.

edit: here's another good one.

edit: and a long and confusing one.

:)
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Also if you look there is a man page for the [ command, it's the same as the test command but looks better in most programming constructs. And after looking at the man page again -e or -b might be a better option to use.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Originally posted by: cmv
You could also toss a "sleep x" in there were x is in seconds in the case you don't want it to try to keep mounting it forever.

You know, you bring up a good point. I wonder if I could make the "until" statement have a time limit on how long it waits, just in case the snaphot fails to get created for some reason...

edit: bummer, "man until" returns nothing...

edit: also, wouldn't it make more sense to do this?
until [ -f /dev/${DEV}1 ]; do

sleep 1

done

mount -t ext3 /dev/${DEV}1 /export/snaps/$SNAP -o ro,acl,user_xattr
?

Now, I can't find documentation on this, but can't you use double pipes as an OR operator? so I could do something like
until [ -f /dev/${DEV}1 || $COUNTER = 10 ]; do
and add an counter increment to the loop?
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
You know, you bring up a good point. I wonder if I could make the "until" statement have a time limit on how long it waits, just in case the snaphot fails to get created for some reason...

Easier to implement would just be an attempt limit, say 5 tries and then it gives up.

edit: bummer, "man until" returns nothing...

'man builtins' will give you the builtin functions of bash.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: Brazen
Originally posted by: cmv
You could also toss a "sleep x" in there were x is in seconds in the case you don't want it to try to keep mounting it forever.

You know, you bring up a good point. I wonder if I could make the "until" statement have a time limit on how long it waits, just in case the snaphot fails to get created for some reason...

edit: bummer, "man until" returns nothing...

edit: also, wouldn't it make more sense to do this?
until [ -f /dev/${DEV}1 ]; do

sleep 1

done

mount -t ext3 /dev/${DEV}1 /export/snaps/$SNAP -o ro,acl,user_xattr
?

Now, I can't find documentation on this, but can't you use double pipes as an OR operator? so I could do something like
until [ -f /dev/${DEV}1 || $COUNTER = 10 ]; do
and add an counter increment to the loop?
Read more of "man [" to figure out ors. Obviously pipes would be interpreted as pipes which make no sense here. Also, your 'until' example should work as a 'while not' type of thing (also see "man [" for the not operator).
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Originally posted by: kamper
Read more of "man [" to figure out ors. Obviously pipes would be interpreted as pipes which make no sense here. Also, your 'until' example should work as a 'while not' type of thing (also see "man [" for the not operator).

'||' is kind of the opposite of '&&'.

rm file || echo "WARNING: File doesn't exist"
If the rm fails, you should see "WARNING: File doesn't exist" outputted to the screen. If the rm succeeds, then you will not see the warning.

Unless of course the || takes on a new meaning inside of the [...
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Originally posted by: n0cmonkey
Originally posted by: kamper
Read more of "man [" to figure out ors. Obviously pipes would be interpreted as pipes which make no sense here. Also, your 'until' example should work as a 'while not' type of thing (also see "man [" for the not operator).

'||' is kind of the opposite of '&&'.

rm file || echo "WARNING: File doesn't exist"
If the rm fails, you should see "WARNING: File doesn't exist" outputted to the screen. If the rm succeeds, then you will not see the warning.

Unless of course the || takes on a new meaning inside of the [...

You might say it is meant as an OR operator when string commands together too? For instance: "this && this && this" means "do this AND this AND this" while "this || this || this" means "do this OR this OR this" but I never thought of it that way before so maybe I'm stretching it a bit.

I found an "Advanced Bash Scripting Guide" that looks pretty comprehensive. I'll have to read it and hopefully it will have info on AND and OR inside loop tests.

Originally posted by: kamper

Read more of "man [" to figure out ors. Obviously pipes would be interpreted as pipes which make no sense here. Also, your 'until' example should work as a 'while not' type of thing (also see "man [" for the not operator).
from the man:
EXPRESSION1 -a EXPRESSION2
both EXPRESSION1 and EXPRESSION2 are true

EXPRESSION1 -o EXPRESSION2
either EXPRESSION1 or EXPRESSION2 is true
Yep. I did skim over the whole thing. I guess I missed these :eek: Thanks!
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: n0cmonkey
Originally posted by: kamper
Read more of "man [" to figure out ors. Obviously pipes would be interpreted as pipes which make no sense here. Also, your 'until' example should work as a 'while not' type of thing (also see "man [" for the not operator).

'||' is kind of the opposite of '&&'.

rm file || echo "WARNING: File doesn't exist"
If the rm fails, you should see "WARNING: File doesn't exist" outputted to the screen. If the rm succeeds, then you will not see the warning.

Unless of course the || takes on a new meaning inside of the [...
Whoops, I knew about && but not about ||. My bad. But still, the || would be interpreted by the shell and anything after it as a new command right? Then test would fail because it has incomplete arguments. So what's needed is something that can be passed as an argument to test (-o in this case).