2014-09-29 72 views
0

整個腳本運行良好。我還會注意到,如果我將cron作業複製並粘貼到shell中並手動運行,則不會有問題。在cron中Git fetch失敗。手動運行良好

Base = '/home/user/git/' 
GIT_out = Base + ("git_file.txt") 
FILE_NAME = Base + 'rules/file.xml' 
CD_file = open(Base + "rules/reports/CD.txt", 'r') 


os.chdir(Base + 'rules') 
gitFetchPull = "git fetch --all ;sleep 3 ; git pull --all" 
git1 = subprocess.Popen(gitFetchPull, shell=True, stdout=subprocess.PIPE) 
gitOut = git1.stdout.read() 
print(gitOut) 

當我看到從cron它似乎不能夠驗證輸出

Received disconnect from 172.17.3.18: 2: Too many authentication failures for tyoffe4 
fatal: The remote end hung up unexpectedly 
error: Could not fetch origin 

cron作業

* * * /usr/bin/python /home/tyoffe4/git/rules/reports/cd_release.py >/home/tyoffe4/git/rules/reports/cd_release.out 2>&1 
+0

什麼是git遠程配置?你使用什麼交通工具? – isedev 2014-09-29 20:22:39

回答

3

這可能是不具有cron的環境問題環境變量由你的ssh代理設置。因此,當git建立一個ssh連接時,它不能進行身份驗證,因爲它不能聯繫你的ssh代理並獲得密鑰。

這個答案可能有你在找什麼: ssh-agent and crontab -- is there a good way to get these to meet?

如果由於某種原因,它是不相關的ssh-agent,嘗試print os.environ在你的腳本的頂部轉儲所有環境變量的值。

比較cron的輸出結果,並在bash shell中運行env。有可能有一些差異,其中之一是你的錯誤的來源。

如果您在shell中設置了與cron中相同的環境變量,則應該重現該行爲。

相關問題