2013-08-03 24 views
0

運行Python讓我先說我非常新的使用Python和創建一個crontab開始了。創建crontab來Dreamhost上

主要有使用本教程 http://wiki.dreamhost.com/Python#Automatic_Installation 運行Python腳本後,這是很容易在我的Dreamhost的帳戶創建一個自定義的Python環境。通常我只需要輸入這個每當我有一個新的會話。

source /home/emre801/.bashrc 

pb switch 2.7.3 

然後,我只是用這個

pb py code.py 

的問題是運行任何Python腳本,當我嘗試創建一個crontab,我現在有這個權利在我的crontab。

*/10 * * * * source /home/emre801/.bashrc; pb switch 2.7.3;pb py code.py 

此代碼的郵件我下面的輸出

/bin/sh: pb: command not found 

我的問題是我怎麼可以設置它的源正確地不給我這個錯誤?

任何幫助是極大的讚賞

回答

2

只是爲此創建bash腳本:

/home/emre801/run.sh

#!/bin/bash 

source /home/emre801/.bashrc 
pb switch 2.7.3 
pb /full/path/to/your/code.py 

使其可執行:

$ chmod 755 /home/emre801/run.sh 

並把它添加到crontab :

*/10 * * * * /home/emre801/run.sh 

*/10 * * * * bash /home/emre801/run.sh 
+1

cron的使用非常簡單和有限的殼(通常不bash的,在這種情況下'/斌/ sh'),所以這就是爲什麼使用這個腳本會解決這個problem--的家當線迫使其與bash shell的,而不是cron的外殼來解釋。 – kevinsa5