Score:0

crontab fails to write logs

cn flag

I'm using crontab to run a python script every minute. This is my how my crontab file looks like:

*/1 * * * *  source /root/.bashrc && source /home/env/bin/activate && python /home/manage.py shell < /home/script.py  >> /var/log/navjob.log 2>&1

When try to check cron output in syslog with this command #grep CRON /var/log/syslog the output is like this:

...CRON[764888]: (root) CMD (source /root/.bashrc && source /home/env/bin/activate && python /home/manage.py shell < /home/script.py  >> /var/log/navjob.log 2>&1)
...CRON[764887]: (CRON) info (No MTA installed, discarding output)

But the log file (/var/log/navjob.log) is empty and the code is not run!

Score:2
hr flag

When you chain commands and add redirection like

cmd1 && cmd2 && cmd3 >> somefile 2>&1

(or cmd1 ; cmd2 ; cmd3 >> somefile 2>&1 etc.) the redirections only apply to the last command in the chain. To redirect all of them, you need to group the commands like

{ cmd1 && cmd2 && cmd3 ; } >> somefile 2>&1

or (with a subshell)

( cmd1 && cmd2 && cmd3 ) >> somefile 2>&1

In this case, your cron job is likely failing at the very first source command, since source is a bashism and cron's default shell is /bin/sh - either add SHELL=/bin/bash before the crontab entry, or change source to the POSIX .

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.