I'm inspecting /var/spool/cron/atjobs/a001cf01570e44 with cat, after running the at command from PHP using exec().

It looks like at has prepended the script with lots of APACHE environment variables.

# atrun uid=33 gid=33
# mail www-data 0
umask 22
APACHE_RUN_DIR=/var/run/apache2; export APACHE_RUN_DIR
APACHE_PID_FILE=/var/run/apache2.pid; export APACHE_PID_FILE
PATH=/usr/local/bin:/usr/bin:/bin; export PATH
APACHE_LOCK_DIR=/var/lock/apache2; export APACHE_LOCK_DIR
LANG=C; export LANG
APACHE_LOG_DIR=/var/log/apache2; export APACHE_LOG_DIR
PWD=/home/jordanarseno/webroot/public_html/myapp; export PWD
cd /home/jordanarseno/webroot/public\_html/myapp || {
     echo 'Execution directory inaccessible' >&2
     exit 1
curl -k http://localhost/myapp/crons/this_action/3

The last line is the only real command I sent along with at via stdin. What is the purpose of these variables? Where is this procedure stored?


When you invoke the at command it copies the current environment so that's what you're seeing.

The working directory, the environment (except for the variables TERM, DISPLAY and _) and the umask are retained from the time of invocation.

You are running at in a php script via apache so what you are seeing in the script is the environment etc that apache is running in.

  • Thanks, what's the purpose though... What was the motivation for at to do this? And can I suppress them?... Or would it be wise not to do so? What is a command I could have handed to exec() that would be dependable on these variables? The reason I ask is I may have many scripts in the atjob directory and I'd like to keep them a small filesize. Sep 29 '12 at 21:28
  • @JordanArseno: The purpose is so that your command/script runs in the same environment as the account that added it to the queue. Cron runs jobs under a restricted environment - you wouldn't believe the number of questions we get here which are solved because the cron job environment is different from the OPs command line environment - at doesn't suffer from this problem. Your script above is 633 bytes - on any reasonably modern system you'd need billions of jobs to cause space problems surely?
    – user9517
    Sep 29 '12 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.