Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

#!/bin/sh
# 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_RUN_USER=www-data; export APACHE_RUN_USER
APACHE_RUN_GROUP=www-data; export APACHE_RUN_GROUP
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?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
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. –  Jordan Arseno 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? –  Iain Sep 29 '12 at 21:49
    
Thanks @Iain!!! –  Jordan Arseno Sep 29 '12 at 21:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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