Hello,

I'm trying to write a bash script for a back up job. Unfortunately I'm not getting 
anywhere.


>I need to mount a file system only if the filesystem is 
>_not_ already mounted.
>
>I'm thinking of it like this:

Ok, I've been reading documentation and wrote a test script. I've so far managed to 
make it like this:

#!/bin/bash


if [ -n `mount |grep "/mnt/root/cschomeserver/e"` ] #if it's already mounted don't 
mount it
    then PREMOUNTED='YES' && echo "is mounted" #If it's already mounted set a var
    else echo "mount /mnt/root/cschomeserver/e is not mounted" #if it's not mounted, 
mount it.
fi
echo $PREMOUNTED


Unfortunately it seems that -n is exactly the opposite of what I need because the 
output is backwards. Additionally, it was working backwards but without error a minute 
ago and now it's giving that "too many arguments" thing - I'm not sure what's changed, 
I tried undoing my (very small) edits to the file and it's still erroring even after 
the un-do so I'm not sure what happened.

When it really is mounted I get the following output from that script:

fluorite:~ # ./test.sh
./test.sh: [: too many arguments
mount /mnt/root/cschomeserver/e is not mounted

Which is backwards - it is mounted. As you can see PREMOUNTED doesn't get set either - 
again, that's backwards.

Then when it really isn't mounted the script _does_  set the var:

fluorite:~ # umount /mnt/root/cschomeserver/e/
fluorite:~ # ./test.sh
YES

So, can someone tell me what the opposite of -n is? According to the man page it's -z 
but that's acting the same as -n (weird) I can't figure it out. I've tried  -n, -z and 
a host of other options I see in the man page and none of it's working and it's 
backwards both ways.

Also can anyone explain the "too many arguments" part - are you not allowed to run a 
command inside [] for output?

I'm also testing it with the interactive shell, such as the following variation:

fluorite:~ # if test -n $( `mount |grep "/mnt/root/cschomeserver/e"` ) ;  then 
PREMOUNTED="YES" && echo $PREMOUNTED ; else echo "no" ; fi
YES

Unfortunately this (and test -z) is always returning "YES" so something's still quite 
wrong.

Obviously I do not understand how to properly get a yes/no value out of the string 
returned from a nested command. If someone could explain even that much I'd appreciate 
it.

TIA


----------------------------------------------------
Jonathan Wilson
System Administrator

Cedar Creek Software     http://www.cedarcreeksoftware.com
Central Texas IT     http://www.centraltexasit.com



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to