【发布时间】:2017-02-16 10:12:36
【问题描述】:
我将使用 cronjob 运行带有参数的 python 脚本。 参数为脚本中需要使用的数据库密码。
#!/usr/bin/python
import MySQLdb
import requests
import json
import os
import sys
param=sys.argv
password=param[1]
db = MySQLdb.connect(host="host.com",port=3306,user="user",passwd=password,db="db")
/etc/crontab:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# * * * * * user-name command to be executed
crontab -e
*/5 * * * * /home/test/run.py "dbpass'"
哪个蟒蛇:
/usr/bin/python
/var/spool/mail 中的错误
/bin/sh: dbpass': command not found
如果我手动运行脚本,它可以正常工作:python run.py "dbpass'"
任何帮助将不胜感激。
【问题讨论】:
-
该错误表明 cron 尝试使用“dbpass”作为命令。您确定这是在用户 crontab 中,而不是在系统范围 (/etc/crontab) 中,它需要用户名作为第 6 个字段?
-
@mata 嗨,感谢您的命令。是的,我把它放在没有用户名的 crontab -e 中。