我有一个脚本,它应该使用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 )
知道是什么了。我把任务当作系统来运行。我在管理员帐户下设置了ssh密钥,但没有设置system。所以ssh在提示处挂起以保存密钥。在
“*”字符可能由Windows shell解释并展开。 试着:
相关问题 更多 >
编程相关推荐