6

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.

Terrence Brannon
  • 4,760
  • 7
  • 42
  • 61

1 Answers1

6

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.

Anubis
  • 6,995
  • 14
  • 56
  • 87
  • 3
    The problem is the order of expansion (tilde expansion before variable expansion) in this line: `cd $ST/src/`. See: https://stackoverflow.com/q/32276909/3776858 – Cyrus Jul 30 '17 at 15:09
  • 2
    Tilde expansion is not specific to `bash`. – chepner Jul 30 '17 at 17:01