I had the following lines in my crontab:
PY=/home/schemelab/install/miniconda/bin/python
ST=~/prg/surgetrader
# SURGE TRADER
00 * * * * cd $ST/src/ ; $PY download.py; $PY scan.py --buy 1
And when it ran the error message in my email was:
X-Cron-Env: <GT=~/prg/gridtrader>
X-Cron-Env: <AGT=~/prg/adsactly-gridtrader>
X-Cron-Env: <PY=/home/schemelab/install/miniconda/bin/python>
X-Cron-Env: <ST=~/prg/surgetrader>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/schemelab>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=schemelab>
Date: Sun, 30 Jul 2017 09:50:02 -0400 (EDT)
/bin/sh: 1: cd: can't cd to ~/prg/surgetrader/src/
/home/schemelab/install/miniconda/bin/python: can't open file 'takeprofit.py': [Errno 2] No such file or directory
However, the path certainly does exist. I think that the tilde is not being expanded or something.
* * * * * is a cron schedule expression wildcard, meaning your cron job should run every minute of every hour of every day of every month, each day of the week.
Crontab Variables The default path is set to PATH=/usr/bin:/bin . If the command you are executing is not present in the cron specified path, you can either use the absolute path to the command or change the cron $PATH variable. You can't implicitly append :$PATH as you would do with a regular script.
One of the most frequent causes for the crontab job not being correctly executed is that a cronjob does not run under the user's shell environment. Another reason can be – not specifying the absolute path of the commands used in the script.
To check to see if the cron daemon is running, search the running processes with the ps command. The cron daemon's command will show up in the output as crond. The entry in this output for grep crond can be ignored but the other entry for crond can be seen running as root. This shows that the cron daemon is running.
Tilde ~
resolution is a bash feature. However your cronjob is not executed through Bash (You could do it explicitly if you want). However you can use $HOME
to refer to the user home independently of the shell.
Refer to Bash reference manual for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With