Please specify (single) host string for connection:

NO IMAGE
1 Star2 Stars3 Stars4 Stars5 Stars 給文章打分!
Loading...

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)  

這樣就可以非常完美的執行了

相關文章

程式語言 最新文章