我的crontab脚本是这样的,每分钟进入
/home/ubuntu/python/env
虚拟环境执行一次
/home/ubuntu/python/Test/run.py
# Begin Plan generated jobs for: main
* * * * * cd /home/ubuntu/python && source env/bin/activate && python Test/run.py
# End Plan generated jobs for: main
在
/var/log/cron.log
查看到的日志如下
Oct 6 04:09:01 ip-172-31-43-145 CRON[2855]: (ubuntu) CMD (cd /home/ubuntu/python && source env/bin/activate && python Test/run.py)
Oct 6 04:09:01 ip-172-31-43-145 CRON[2854]: (CRON) info (No MTA installed, discarding output)
Oct 6 04:10:01 ip-172-31-43-145 CRON[2857]: (ubuntu) CMD (cd /home/ubuntu/python && source env/bin/activate && python Test/run.py)
Oct 6 04:10:01 ip-172-31-43-145 CRON[2856]: (CRON) info (No MTA installed, discarding output)
但是
run.py
并没有执行,如果单独执行下面语句,则可以执行成功
$ cd /home/ubuntu/python && source env/bin/activate && python Test/run.py
why, any body help me?
还是让crontab执行shell,然后在shell脚本中执行python,可行:http://blog.bomobox.org/2016-10-06/crontab-python/
试试这个呢:
cd /home/ubuntu/python && /home/ubuntu/python/env/bin/python Test/run.py
YOU CAN TRY
* * * * * cd /home/ubuntu/python && source env/bin/activate && python Test/run.py >> /home/ubuntu/python/crond.log