I was doing some more cron work and was reminded that I never posted the detail
I had in mind. Here's how I got the lowdown on the cron shell environment...
I setup a temporary cron job to invoke a shell script to create a little web page:
- Code: Select all
#!/bin/bash
DIR="/home/radilly/html/test"
OUT_FILE="${DIR}/cron_env_check.htm"
touch ${OUT_FILE} ; # create file if it doesn't exist
echo "<PRE>" >> ${OUT_FILE}
echo "<B> env </B>" >> ${OUT_FILE}
env | sort >> ${OUT_FILE}
echo "<B> which convert / version </B>" >> ${OUT_FILE}
which convert >> ${OUT_FILE}
convert -version >> ${OUT_FILE}
echo "<B> which mogrify / version </B>" >> ${OUT_FILE}
which mogrify >> ${OUT_FILE}
mogrify -version >> ${OUT_FILE}
The output looks something like:
- Code: Select all
env
HOME=/home/radilly/
LOGNAME=radilly
MAILTO=
PATH=/usr/bin:/bin
PWD=/home/radilly/
SHELL=/bin/sh
SHLVL=3
USER=radilly
_=/usr/bin/env
which convert / version
/usr/bin/convert
Version: ImageMagick 5.5.6 04/01/03 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 2003 ImageMagick Studio LLC
which mogrify / version
/usr/bin/mogrify
Version: ImageMagick 5.5.6 04/01/03 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 2003 ImageMagick Studio LLC
The
interesting results are the PATH and PWD variables and the which command output.
Under cron we see:
PATH=/usr/bin:/binWhen I login interactively I see:
PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/radilly/binAny script or command not in /usr/bin or /bin would need the full path spelled
out explicitly when running under cron. In a login shell, 3 additional locations are
searched. It would be unusual for tools and utilities to be found in /usr/local/bin
The cron process will typically log into my HOME directory:
/home/radilly/but my script ... or at least the interactive commands which worked, ran in
/home/radilly/html/testWhen I reference at files in this directory under cron, I need to either give the
full path, or the relative path
html/test. I prefer the former. (
This, BTW
is where I messed up in my first attempt.)
Finally
which convert prints the full path to c[url][/url]onvert.
/usr/bin/convertActually, the fact that the path was printed means
/usr/bin is in the PATH.
Were it not, which would fail. It actually makes more sense to run
which convertin a login shell and note the path. Technically you shouldn't need the path in this
environment, but I would tend to specify it, i.e.
/usr/bin/convert rather
than just
convert.
It's a little work, but running a little test script (repeatedly if need be) under cron
has almost always help me dope out what's going on.
Bob
FYI- my application was to make a 50% version of a web cam image to post on
http://www.the-dillys.org/WX/. I could resize in the html, but I
wanted to minimze the upload time. On average they should be 1/4 the file size.