python ssh/rsync在以windows servi运行时挂起

2024-09-30 20:35:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个脚本,它应该使用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 )   

Tags: 文件self脚本机器binlinuxwindowsservice
2条回答

知道是什么了。我把任务当作系统来运行。我在管理员帐户下设置了ssh密钥,但没有设置system。所以ssh在提示处挂起以保存密钥。在

“*”字符可能由Windows shell解释并展开。 试着:

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

相关问题 更多 >