[SATLUG] small script, baffled problem.

David Kowis dkowis at shlrm.org
Wed Aug 11 17:59:04 CDT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 08/11/2010 04:26 PM, Richard Suberg wrote:
> I can't find anything anywhere that helps me out with this one.  I have a
> simple script that mounts by ftp and then copies data from that server to
> mine. Problem is if the mount fails (other server changes password or just
> connect fails) it wipes out the destination and doesn't tell me anything. I
> decided to add an if clause after the mount, and after that on failures I
> get either syntax error near unexpected token '}' or near unexpected token
> 'fi' or near unexpected token 'else'.  I even run into unexpected end of
> file, just depends on what is at the end of the file.  I would like to have
> an error-processing routine that would let me know somehow that it failed,
> but if it just skips the copy on mount failed that would be better than
> nothing.
> 
>  
> 
> I'm totally baffled, and just see how many hits you get trying to search for
> if then else ubuntu.even tried what I found there, (using brackets, fi, .)
> and no help. Hopefully someone can see the problem easily. 
> 
>  
> 

Simple fix: you forgot a semicolon

if $?=0 ; then

if and then are separate statements, so they have to have a semicolon or
be on different lines.

Also, when you test your exit=? that changes the exit code, better would
be to store your exit code immediately
EXIT_CODE=$?

echo "exit = $EXIT_CODE"

Also I wouldn't put the exit 0 in there, I'd let it fall out normally :)

> - - - - -
> 
> curlftpfs 205.145.4.35 /remote -o allow_other,user=user:pass  -v
> 
> echo exit=$?
> 
> if  $?=0   then 
> 
>  echo Processing...
> 
>  date
> 
>  cp -uRv /remote/* /share/DSD/ 
> 
>  chmod -R 777 /share
> 
>  umount /remote
> 
>  echo done
> 
>  exit 0 
> 
> fi
> 
>  
> 
>  
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iQGcBAEBAgAGBQJMYys4AAoJEMnf+vRw63ObzuYL/0ZNdaEcCBr50ApgXf8g470m
ZfDIyIRPXHlrcNniSmUVLf06T6W5cvaK3v/NYmmoIn9BNOSnWXa9qLAbqohXyISG
spvSKlHSBITd161NUb8npf3+Hyi3dJj7apZJC2A956IhBwJPzGnlzHGotBHpm1w4
F+d4ERvvHPKUYZ0YzobZlk62BpnMR0kav7xDIoOocicCRjMnZOHHjt/I5C7HrgPB
Sr90KtNxiuoHCIesZRKpoZlb6d4a/0AUWppr3ICbWYZgXy40RPrKTrD+ZKmr0lrn
oLEHYpC9J8PePutwZ1McMaimjM96Iz+KkR95HU02G4MYNnZPoId6k9pOmTQhYqWU
6r983dQEg3fsEy3MHqWmX09dxSdsQi+GCyEapMD+CtYVp47hCb6mnAjvKKfIPznL
/QvTRSnIlnRbgnkfSxdcr/eOAywUMglNZZqyiWy1NfnGCyyl+bhBefvU1EpoQPtj
agA5RCQsOodcqCV++L8FY3iCnPuivKf4ALIXa1P3mw==
=EId1
-----END PGP SIGNATURE-----


More information about the SATLUG mailing list