at and cron annoyingly different

Chris F.A. Johnson chris-E7bvbYbpR6jSUeElwK9/Pw at public.gmane.org
Thu Nov 17 04:03:27 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.

    The two commands are very different. Crontab does not run a
    command; it inserts a command into a file which is later read by
    cron. Each line in a crontab file could have been entered when in a
    different directory; that information is not stored in the file.

-- 
    Chris F.A. Johnson, <http://cfajohnson.com/>
    Author:
    Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
--
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