开发者

Writing a Cron Job That Can Access User Data

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 m开发者_StackOverflow社区anually, 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)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜