0

I am trying to schedule a one time job with the at utility. I am trying: at 13:00, then hitting enter, then <name_of_shell_script>, then ctrl+d.

The top line of my script is: #!/bin/zsh

but it is never executed. It executes when run manually, but not when scheduled with the at utility.

1 Answer 1

-2

Jobs run through cron, or at, or batch, aren't run in the same runtime environment that you have on your desktop. None of your PATH changes, or other environment variable settings are automatically propagated to your cron job. For example, there's no $DISPLAY, so GUI programs need special treatment (read man xhost).

One can set environment variables for all one's cron jobs in the crontab file Read man 5 crontab.

Look at the results of echo "=== set ===";set;echo "=== env ===";env | sort;echo "=== alias ===";alias in each of your environments.

Since the command part of the crontab line is, by default, interpreted by /bin/sh, which has a simpler syntax than /bin/bash, I recommend having command be a call to a bash script (executable, mounted, starts with #!/bin/bash) which sets up the environment, then calls the desired program.

3
  • Hmm... I (largely) agree with you about cron, but are you sure the same applies to at? The man page on my system says "The working directory, the environment (except for the variables BASH_VERSINFO, DISPLAY, EUID, GROUPS, SHELLOPTS, TERM, UID, and _) and the umask are retained from the time of invocation.". Also, why should the command be a bash script specifically, rather than the zsh script the OP is already using? Commented May 12, 2021 at 22:56
  • @steeldriver: I recommend bash because it's a simple answer, and is a valid login shell (is in /etc/shells). Substitute any shell you like. It's a canned answer that I reuse. These "cron, at, batch, questions are so prevalent that I got tired of rewriting the same explanation. I asked about canned answers on Meta AskUbuntu. Commented May 13, 2021 at 0:52
  • @steeldriver It's title is "Am I a curmudgeon? Should I STFU?". I've continued the practice. Commented May 13, 2021 at 1:05

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.