views:

54

answers:

1

I'm trying to write a cron job that runs a report, and emails the result to an address defined in my user's ~/.bashrc file. I had this working perfectly on Fedora, but when I switched to Ubuntu, my solution no longer works. The command my cron job currently runs is:

. /home/myuser/.bashrc; /home/myuser/bin/runreport

If I run that command manually, or start it via Gnome-Schedule, it works perfectly, but it never seems to run. Is there something specific to Ubuntu that would be blocking this from running?

Output of crontab -l:

0 8 * * * . /home/myuser/.bashrc; /home/myuser/bin/runreport # JOB_ID_1

Output of grep -i cron /var/log/syslog:

Aug  4 08:00:00 localhost CRON[23234]: (myuser) CMD (. /home/myuser/.bashrc; /home/myuser/bin/runreport # JOB_ID_1)
+2  A: 

If /home/myuser/bin/runreport is a script, add the following two lines to the top:

env
set -x

and change the crontab line to:

. /home/myuser/.bashrc ; /home/myuser/bin/runreport >/tmp/qq 2>&1

Then, when it runs, you should have all the environment variables, and the commands that were run, in the /tmp/qq file.

If it isn't a script, make a script that calls it and add the env line to it. That will at least give you the environment you're running in.

paxdiablo
"runreport" is actually a Python script, with "#!/usr/bin/python" at the top. Are there equivalent lines for Python?
Chris S
Chris S
@Chris, you could probably get the environment with `os.system("env")` or just by inserting `env >tmp/qq.env` into your cron command immediately before running `runreport`. The per-line debugging is harder - it's probably easier just to add debug `print` statements to the script. Glad I could help with the pipe issues though. Cheers.
paxdiablo