1
我有一個python腳本任務調度的結果,我想運行每隔幾分鐘從混帳回購這基本上是這樣的拉數據:運行git命令通過權限被拒絕錯誤
import os
import subprocess
import sys
def execute_command(command):
p = subprocess.Popen(command.split(' '), stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
#do some stuff with stdout, stderr - return stderr if it exists
if __name__ == "__main__":
os.chdir("C:\MyGitRepo")
reset_command = "git reset --hard HEAD"
pull_command = "git pull"
reset_stderr = execute_command(revert_command)
pull_stderr = execute_command(pull_command)
#do some stuff with stderrs
我創建了一個ssh密鑰並將其添加到ssh-agent以及託管repo的服務器。當我通過powershell運行腳本時,它工作正常並且回購更新,但是當我通過任務計劃程序設置任務來運行此操作時,會導致權限被拒絕的錯誤。
我已經改變了任務調度的任務,我手動從運行它的帳戶下運行,但仍得到這樣的:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
如何讓腳本以使用正確的密鑰的任何想法?
密鑰是否有密碼?當ssh從任務調度器運行時,ssh可能不知道你的代理。 – Kenster
如果任務使用存儲的密碼,則用戶應該使用加載的用戶配置文件(例如用戶環境變量)登錄並訪問保存的憑證和網絡。但是這個過程在服務會話中運行,所以它不能訪問GUI,包括用於IPC的窗口消息,如果ssh代理需要的話。嘗試配置任務以要求用戶已登錄,該用戶在用戶的交互式會話中運行任務,而不是在服務會話中運行。 – eryksun