at and cron annoyingly different

Lennart Sorensen lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys at public.gmane.org
Thu Nov 17 16:15:55 UTC 2011


On Wed, Nov 16, 2011 at 10:05:08PM -0500, D. Hugh Redelmeier wrote:
> I want to run a cron job in a particular directory.  Running the
> crontab(1) command from that directory isn't enough: the script will
> run with ~ as the current working directory.
> 
> So I wrote the script file for cron in the directory of interest and
> told cron to run it.  In that script, I used
> 	cd `dirname "$0"
> So the script would change the directory to the one containing the
> script.  That worked well.
> 
> For unrelated reasons, the script didn't work, so I fixed it up and
> tried to run it using at(1).
> 
> - at(1) does remember the working directory in which it was run and it
>   runs the script file with that current working directory.  So my
>   tricky cd command wasn't needed for at.
> 
> - at(1) runs the script with $0 set to /bin/bash so my cd is actually
>   very wrong for at.  I don't want /bin as the working directory.

Reading the man page for bash, I don't quite see how at could do that.

> All this I figured out by debugging.  Since the runs were not frequent
> (once a day) debugging was stretched out.
> 
> Surely these related commands could converge so that differences
> between scripts could be minimized.

By design cron runs with a minimal well known environment.

at commands by design are supposed to inherit everything from the
environment where they were scheduled from.

They are very very different and have very different purposes.  They are
not related at all.

-- 
Len Sorensen
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list