/bin/sh Madness

Dan Nelson dnelson at allantgroup.com
Fri Feb 17 15:56:29 PST 2006


In the last episode (Feb 17), Tim Daneliuk said:
> Dan Nelson wrote:
> >Could your $3 command be returning a nonzero exit code?  You probably
> >want something more like
> >
> >touch $2/.$1-begin && { eval $3 2>&1 >> $log ; touch $2/.$1-end } &
> >
> >so your end timestamp always gets created whether or not $3 succeeds.
> >Also note that in your original script, you only backgrounded "touch
> >$2/.$1-end", which is probably not what you wanted.
> 
> This seems not to work - I don't think 'sh' likes nested function
> braces - recall that this command appears inside a shell function.

Oops.  Braces aren't bourne syntax, and in this case they're the wrong
choice anyway.  parens (i.e. a subshell) are what's needed.

touch $2/.$1-begin && ( eval $3 2>&1 >> $log ; touch $2/.$1-end ) &

I actually tested this one :)
 
> In any case, I think I have nailed the problem.  It seems that the
> external script being called made reference to 'chown' without explicitly
> naming the program's path.  Under 'cron' control, there is no path to
> /usr/sbin by default so the script was exiting with a non-zero exit
> status as several here suggested.  <Wipes large glob off egg off very
> red face>.
> 
> Many thanks to all who took time to answer.

-- 
	Dan Nelson
	dnelson at allantgroup.com


More information about the freebsd-questions mailing list