at and cron annoyingly different

gyre-Ja3L+HSX0kI at public.gmane.org gyre-Ja3L+HSX0kI at public.gmane.org
Fri Nov 18 07:04:37 UTC 2011


On Wed, 16 Nov 2011, 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.
>
> 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.

They do work the same for '$0'.

These work fine with `dirname "$0"` inside a script which yields '/tmp':
   echo  /tmp/tmp1.sh | at now
   echo  /tmp/tmp1.sh | batch

And this crontab entry:
   * * * * * echo "dirname dollar0 is "`dirname $0`
produces this mail:
   dirname dollar0 is /bin

Of course, the environments are different; perhaps
a 'cron-once' command would be good.

My pet peeve is to have better integration between cron and
anacron.

And how about a simple method to have cron use UTC, instead of
localtime with its politically arbitrary daylight
saving time rules?


-- 
Eric.
--
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