[Gllug] Bash Question - My Brain's not working tonight

Alain Williams addw at phcomp.co.uk
Sun Aug 26 21:54:37 UTC 2007


On Sun, Aug 26, 2007 at 10:07:09PM +0100, Ken Smith wrote:
> Hi, I writing a simple backup script with bash. But my string 
> programming is all messed up - I'm really inexperienced in this area. 
> The script is to use rsync to backup a CIFS share from a Win box.
> 
> I want to check to see if  the share is already mounted for whatever 
> reason.
> 
> I have the machine name in $1 and the share name is $2
> 
> so what I want to do is
> 
> mount | grep //$1/$2 and then use an if statement based on the value of $?
> 
> where in this case
> 
> $1 is trh2003.trhbeith.local
> 
> and $2 is e$
> 
> and the whole string I'm looking for in the mount output is 
> //trh2003.trhbeith.local/e$
> 
> But somehow the "/'s" are getting mashed somewhere.

Put
	set -x
on the line before -- shell debugging, see what is being substituted/executed.
Note that the RE:
	//trh2003.trhbeith.local/e$
has some meta characters in it:

	.	-- match anything, probably benign
	$	-- match end of string

The $ will cause problems since it says: 'find an 'e' at the end of line'
which is not what you want.

You could try something like:

	mount | grep -q "$( echo "//$1/$2" | sed -e 's/\$/\\$/g' )"

The -q is there because you don't want to see what it finds.

-- 
Alain Williams
Linux Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php
Chairman of UKUUG: http://www.ukuug.org/
#include <std_disclaimer.h>
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list