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