Question

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)
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top