Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux "at" command works fine when running from shell but fails when run from webserver

I'm using "at" in order to set future actions set by users on RHEL6.4. The command I'm using from php is

exec("echo \"php $script_path\" | at $run_time");

where the script path has been set as has the run time. This works 100% fine when I run from a shell initiated with php -a. When it runs from the webserver the job is created, but it doesn't seem to run.

  1. I have verified : The apache user has full read-write-execute access to the directory and all folders therein.

  2. The exec command is running (the at job is created, after all.)

  3. I have verified the job is looking for the right path on the server.

I'm not sure what else I can do to get this at command to run the script properly. Any suggestions?

Thank you for your help.


Update: I went ahead and created a page that linked to the script I'm trying to auto-run and launched it in that way. The script itself works fine when run as apache that way, meaning it's definitely something that "at" is doing. I ran print_r($_ENV) to determine the environment variables being used. The only thing that shows up is a number 1.


Update 2: I ran an at -c on each job, the one that never seems to run, and the one that works just fine. There seems to be much more content on the one that does work VS the one that doesn't. 65 worked (ran from shell)

at -c 65
#!/bin/sh
# atrun uid=0 gid=0
# mail root 0
umask 22
HOSTNAME=ipdb-sys.ipdb.lab; export HOSTNAME
SHELL=/bin/bash; export SHELL
HISTSIZE=1000; export HISTSIZE
SSH_CLIENT=143.166.167.124\ 53008\ 22; export SSH_CLIENT
QTDIR=/usr/lib64/qt-3.3; export QTDIR
QTINC=/usr/lib64/qt-3.3/include; export QTINC
SSH_TTY=/dev/pts/0; export SSH_TTY
USER=root; export USER
LS_COLORS=rs=0:di=01\;34:ln=01\;36:mh=00:pi=40\;33:so=01\;35:do=01\;35:bd=40\;33\;01:cd=40\;33\;01:or=40\;31\;01:mi=01\;05\;37\;41:su=37\;41:sg=30\;43:ca=30\;41:tw=30\;42:ow=34\;42:st=37\;44:ex=01\;32:\*.tar=01\;31:\*.tgz=01\;31:\*.arj=01\;31:\*.taz=01\;31:\*.lzh=01\;31:\*.lzma=01\;31:\*.tlz=01\;31:\*.txz=01\;31:\*.zip=01\;31:\*.z=01\;31:\*.Z=01\;31:\*.dz=01\;31:\*.gz=01\;31:\*.lz=01\;31:\*.xz=01\;31:\*.bz2=01\;31:\*.tbz=01\;31:\*.tbz2=01\;31:\*.bz=01\;31:\*.tz=01\;31:\*.deb=01\;31:\*.rpm=01\;31:\*.jar=01\;31:\*.rar=01\;31:\*.ace=01\;31:\*.zoo=01\;31:\*.cpio=01\;31:\*.7z=01\;31:\*.rz=01\;31:\*.jpg=01\;35:\*.jpeg=01\;35:\*.gif=01\;35:\*.bmp=01\;35:\*.pbm=01\;35:\*.pgm=01\;35:\*.ppm=01\;35:\*.tga=01\;35:\*.xbm=01\;35:\*.xpm=01\;35:\*.tif=01\;35:\*.tiff=01\;35:\*.png=01\;35:\*.svg=01\;35:\*.svgz=01\;35:\*.mng=01\;35:\*.pcx=01\;35:\*.mov=01\;35:\*.mpg=01\;35:\*.mpeg=01\;35:\*.m2v=01\;35:\*.mkv=01\;35:\*.ogm=01\;35:\*.mp4=01\;35:\*.m4v=01\;35:\*.mp4v=01\;35:\*.vob=01\;35:\*.qt=01\;35:\*.nuv=01\;35:\*.wmv=01\;35:\*.asf=01\;35:\*.rm=01\;35:\*.rmvb=01\;35:\*.flc=01\;35:\*.avi=01\;35:\*.fli=01\;35:\*.flv=01\;35:\*.gl=01\;35:\*.dl=01\;35:\*.xcf=01\;35:\*.xwd=01\;35:\*.yuv=01\;35:\*.cgm=01\;35:\*.emf=01\;35:\*.axv=01\;35:\*.anx=01\;35:\*.ogv=01\;35:\*.ogx=01\;35:\*.aac=01\;36:\*.au=01\;36:\*.flac=01\;36:\*.mid=01\;36:\*.midi=01\;36:\*.mka=01\;36:\*.mp3=01\;36:\*.mpc=01\;36:\*.ogg=01\;36:\*.ra=01\;36:\*.wav=01\;36:\*.axa=01\;36:\*.oga=01\;36:\*.spx=01\;36:\*.xspf=01\;36:; export LS_COLORS
WEBROOT=/var/www; export WEBROOT
MAIL=/var/spool/mail/root; export MAIL
PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/dell/srvadmin/bin:/opt/dell/srvadmin/sbin:/root/bin; export PATH
PWD=/root; export PWD
LANG=en_US.UTF-8; export LANG
MODULEPATH=/usr/share/Modules/modulefiles:/etc/modulefiles; export MODULEPATH
LOADEDMODULES=; export LOADEDMODULES
HISTCONTROL=ignoredups; export HISTCONTROL
SHLVL=1; export SHLVL
HOME=/root; export HOME
LOGNAME=root; export LOGNAME
QTLIB=/usr/lib64/qt-3.3/lib; export QTLIB
CVS_RSH=ssh; export CVS_RSH
SSH_CONNECTION=143.166.167.124\ 53008\ 10.180.57.93\ 22; export SSH_CONNECTION
MODULESHOME=/usr/share/Modules; export MODULESHOME
LESSOPEN=\|/usr/bin/lesspipe.sh\ %s; export LESSOPEN
G_BROKEN_FILENAMES=1; export G_BROKEN_FILENAMES
module=\(\)\ {\ \ eval\ \`/usr/bin/modulecmd\ bash\ \$\*\`"
"}; export module
cd /root || {
         echo 'Execution directory inaccessible' >&2
         exit 1
}
${SHELL:-/bin/sh} << 'marcinDELIMITER145f56ce'
php /var/www/ipdb5.0/unattend/release.php

marcinDELIMITER145f56ce

Job 68 didn't.

at -c 68
#!/bin/sh
# atrun uid=48 gid=48
# mail apache 1
umask 22
PATH=/sbin:/usr/sbin:/bin:/usr/bin; export PATH
RUNLEVEL=3; export RUNLEVEL
runlevel=3; export runlevel
PWD=/var/www/ipdb5.0/run; export PWD
LANGSH_SOURCED=1; export LANGSH_SOURCED
LANG=C; export LANG
PREVLEVEL=N; export PREVLEVEL
previous=N; export previous
CONSOLETYPE=vt; export CONSOLETYPE
SHLVL=4; export SHLVL
UPSTART_INSTANCE=; export UPSTART_INSTANCE
UPSTART_EVENTS=runlevel; export UPSTART_EVENTS
UPSTART_JOB=rc; export UPSTART_JOB
cd /var/www/ipdb5\.0/run || {
         echo 'Execution directory inaccessible' >&2
         exit 1
}
${SHELL:-/bin/sh} << 'marcinDELIMITER348f4254'
php /usr/bin/php /var/www/ipdb5.0/unattend/release.php

marcinDELIMITER348f4254

Don't know if you guys can devine any more out of this than I can, but I figured it wouldn't hurt to post to see.

like image 873
Ethan Avatar asked Sep 30 '22 08:09

Ethan


1 Answers

Finally found the answer. It turns out you need three things to be true that I hadn't set before.

  1. You need to have the absolute path to the program you're calling (php had to be /usr/bin/php) - Thanks mti2935.
  2. You need to have a shell set up for your apache user. - Thanks for getting me started in this direction craniumonempty. The command I had to run was : sudo chsh -s /bin/bash username
  3. Lastly you have to have an at.allow file created with the www-data group and apache user in it. (Make sure there is NOT a at.deny file, as this will counteract the allow.).

Once all of these are set the at will run successfully from your webserver. Also, be sure to have the basics which I went over in the main post. Give read/write/execute to apache for the script you're running, make sure the script itself works without running it with at, and verify the at job is being created.

Thank you all for the assistance.

like image 200
Ethan Avatar answered Oct 09 '22 19:10

Ethan