2014-09-29 68 views
0

我已经做了我的剧本很容易在bash - 这脚本应该将该文件与特定的新名称从服务器1传送到远程服务器2bash脚本转移到Python - 从服务器日志复制到另一个远程服务器

灿有人帮助完成并将所有脚本传输到Python。

#!/bin/bash 

path=/opt/log #Im in dir /opt/log 
fdate=$(date +%Y%m%d -d "-1 day") # yesterday date 
file=maillog-$fdate  # log from yesterday which will be transfer to remote server 
cp $path/$file /tmp/$HOSTNAME-$file # copy $file to /tmp with the specific name of $HOSTNAME + $File name 
gzip /tmp/$HOSTNAME-$file  # ZIP the file 

[email protected] # remote server 
rpath=/opt/log/maillog # remote path 

scp /tmp/$HOSTNAME-$file.gz $rserver:$rpath # copy the file to remote server to remote path 

rm /tmp/$HOSTNAME-$file.gz # clean the /tmp dir 
#Done 
+0

这样的回答可以帮助你: http://stackoverflow.com/questions/250283/how-to-scp-in-python – jgritty 2014-09-29 17:59:54

+0

你好这是有帮助但最后一件事我需要写而不是fdate = $(日期+%Y%m%d -d“-1天”)#昨天日期 - 这是fdate =昨天日期“格式的日期命令+%Y%m %d - 1天,怎么可能在Python中创建这个? – hansus 2014-09-30 09:36:25

+0

试试这个答案http://stackoverflow.com/questions/441147/how-can-i-subtract-a-day-from-a-python-日期 – jgritty 2014-09-30 16:59:51

回答

0

有几种解决方案。

一种选择是异口同声:

http://xmodulo.com/synchronize-files-between-two-servers.html

rsync的解决方案:

您需要ssh到服务器第一个(这应该是微不足道)。一旦进入你可以运行这个。

rsync -rtlzv --ignore-errors -e ssh . [email protected]:/path/to/directory 

来自:http://darcynorman.net/2009/01/07/how-i-move-stuff-between-servers-with-rsync/

的SCP解决方案:

其实,我觉得这是最优雅的方式,因为你没有在第一个SSH协议。 Somethibng这样的:

nohup scp [email protected]:/the/answer/of/all [email protected]:/var/tmp/42 & 

来自:https://unix.stackexchange.com/questions/65116/does-a-scp-transfer-close-when-i-close-the-shell

相关问题