cron job verification
Derek Martin
invalid at pizzashack.org
Wed Feb 2 13:35:01 EST 2005
On Wed, Feb 02, 2005 at 10:45:31AM -0500, Bob Bell wrote:
> On Wed, Jan 12, 2005 at 12:15:46AM -0500, Derek Martin wrote:
> > #!/bin/sh
> > # NEVER start shell scripts as #!/bin/bash -- it can lead to strange
> > # and unintended results.
>
> Like what? I've never had a problem. If I specifically am using bash
> features, I always say "/bin/bash", as "/bin/sh" could mean Bourne shell
> or POSIX shell.
If you invoke bash as /bin/bash, it will source all your environment
files (usually just your .bashrc, since normally it won't be invoked
as a login shell in this manner). This can cause unintended effects.
I ran into this problem when I installed Debian 2.2 on one of my
systems. When I logged into the system, IIRC X started up but I
couldn't do anything in any of the xterms I started... That is, I
never got a prompt, and the system came to a grinding halt. I was
able to log in at a virtual console and see what was going on.
In my .bashrc file, I had some code that used the which command to set
some variables. On Debian 2.2, the which command was a shell script
which was invoked as #!/bin/bash. This was causing an infinte loop,
where a bazillion /usr/bin/which processes were running and not
completing.
IIRC the most bizarre part of this was that if I logged in (as myself)
on the console, the effects were different than if I logged in under
X. I was never able to determine why. Note that I set the resource
XTerm*loginShell: true
in my .Xdefaults file, so there should be no difference (that I can
think of) between my xterm shells and one started on a VC.
> > rsync <options>
> > if ! $? ; then
> > echo -e "\nrsync completed successfully!\n"
> > else
> > echo -e "\nrsync failed!\n!"
> > fi
>
> That won't work. As you said, $? will evaluate to an integer, which the
> shell will then (unsuccessfully) try to execute. You want either:
You're right, sorry! My shell coding is a bit rusty these days. :(
This is the one I meant:
> if [ $? -eq 0 ] ; then
--
Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0xDFBEAD02
-=-=-=-=-
This message is posted from an invalid address. Replying to it will result in
undeliverable mail. Sorry for the inconvenience. Thank the spammers.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.gnhlug.org/mailman/private/gnhlug-discuss/attachments/20050202/4b8da4a9/attachment.bin
More information about the gnhlug-discuss
mailing list