python ssh/rsync在作为windows服务运行时挂起

python ssh/rsync在作为windows服务运行时挂起,python,windows,service,ssh,rsync,Python,Windows,Service,Ssh,Rsync,我有一个脚本,它应该使用rsync将文件从Linux设备拉到我的Windows设备。我把它设计成一个Windows服务,这一点似乎很好。rsync和ssh可执行文件启动,连接到Linux机器,使用密钥进行身份验证,但不要复制任何文件。 这里是脚本的核心,不包括大多数Windows服务内容 import subprocess RSYNCPULL = '''"C:\\Program Files\\cwRsync\\bin\\rsync.exe" --remove-source-files

我有一个脚本,它应该使用rsync将文件从Linux设备拉到我的Windows设备。我把它设计成一个Windows服务,这一点似乎很好。rsync和ssh可执行文件启动,连接到Linux机器,使用密钥进行身份验证,但不要复制任何文件。 这里是脚本的核心,不包括大多数Windows服务内容

import subprocess
RSYNCPULL = '''"C:\\Program Files\\cwRsync\\bin\\rsync.exe" --remove-source-files
           --no-motd -e "\'C:\\Program Files\\cwRsync\\bin\\ssh.exe\'"
           user@IP:/var/log/* /cygdrive/c/logs/'''

class LogCopy( win32serviceutil.ServiceFramework ):
   #various functions for starting/stopping the service
    def sleep( self, sec ):
        win32api.Sleep( sec*1000, True )
    def start( self ):
        self.runflag = True
        while self.runflag:
            subprocess.call( RSYNCPULL )
            self.sleep( 10 )  

if __name__ == "__main__":
    qin32serviceutil.HandleCommandLine( LogCopy )   
“*”字符可能由Windows shell解释并展开。 试着:

  • 在“*”前面加一个反斜杠。这样,rsync将在连接的另一端为您扩展它
  • 删除“*”,然后使用rsync的-r选项对目录进行递归复制

    • 找到了那是什么。我是作为系统运行任务的。我在管理员帐户下安装了ssh密钥,但在系统中没有。因此ssh在保存密钥的提示下挂起