Crontab syntax; Multiple commands
I would like to get the following chain of commands as a cronjob:
* * * * * source activate myenv3 && cd ~/foo/bar && python sssb.py
It works in console, but I dont get any output from the cronjob.
I followed this suggestion, by replacing it with
* * * * * env > /tmp/env.output
to find out whether env is different. I couldn't find anything relevant besides PATH being different. So then I set up
PATH=myPath
* * * * * source activate myenv3 && cd ~/foo/bar && python sssb.py
and it still didn't work. Finally I replaced it with
PATH=myPath
* * * * * source activate myenv3 && cd ~/foo/bar && python sssb.py
* * * * * env > /tmp/env.output
and this time I didn't even get the env.output
file. Hence I think there's something wrong with my syntax - but it looks exactly like the multi-command suggestions I found online.
What's going on here? If it's not obvious, what can I next to trace out the error?
PATH=/usr/local/anaconda2/envs/myenv3/bin:~/.conda:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
out.err
:
/bin/sh: 6: /usr/local/anaconda2/envs/myenv3/bin/activate: [[: not found
/bin/sh: 15: /usr/local/anaconda2/envs/myenv3/bin/activate: [[: not found
/bin/sh: 17: /usr/local/anaconda2/envs/myenv3/bin/activate: [[: not found
Only bash and zsh are supported
In Ubuntu, by default, the cron
daemon runs all the jobs using sh
(dash
) shell and dash
does not have source
builtin.
You need to use the POSIX way i.e. .
:
* * * * * . activate myenv3 && cd ~/foo/bar && python sssb.py
Alternately, you can run the job as an argument to bash
:
* * * * * "$(command -v bash)" -c 'source activate myenv3 && cd ~/foo/bar && python sssb.py'