为什么在此Cron作业中带波浪号的有效路径没有扩展? [英] Why is a valid path with a tilde not expanding in this cron job?
本文介绍了为什么在此Cron作业中带波浪号的有效路径没有扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的crontab中有以下几行:
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.
推荐答案
波浪符〜
分辨率是一项bash功能。但是,您的cronjob不是通过Bash执行的(如果需要,可以显式执行)。但是,您可以使用 $ HOME
独立于外壳程序来引用用户主目录。
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.
请参考 Bash参考手册以获取更多信息。
Refer to Bash reference manual for more info.
这篇关于为什么在此Cron作业中带波浪号的有效路径没有扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文