No hosts found. Please specify (single) host string for connection:
在apscheduler中执行fabric的定时任务时:
正常的写法是这样的
scheduler.add_job(updataPicture.gettime, 'cron', day_of_week='0-6', hour=18, minute=15)
但是在时间到达的时候执行结果是这样的:
No hosts found. Please specify (single) host string for connection:
结果会让我重新输入主机名
经过查询在Stack Overflow上找了答案:
In order to get hosts to work in a script outside of the fab command-line tool and fabfile.py, you'll have to use execute():
from fabric.tasks import execute
def mytask():
run('uname -a')
results = execute(mytask)
这样的话主机就可以工作在脚本以外了,我在原有fabric文件中执行
def getlatestpics():
execute(updatapic)
然后定时任务这样:
scheduler.add_job(updataPicture.getlatestpics, 'cron', day_of_week='0-6', hour=18, minute=15)
这样就可以非常完美的执行了