[英]Bash script transfer to Python - copy logs from server to another remote server
I have done my easy script in bash - this script should transfer the file with the specific new name from server 1 to remote server 2. 我已经在bash中完成了简单的脚本-此脚本应将具有特定新名称的文件从服务器1传输到远程服务器2。
Can someone help with this and transfer all script to 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
rserver=hansus@hansus.edu.net # 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
There are several solutions to this. 有几种解决方案。
One option is unison: 一种选择是统一:
http://xmodulo.com/synchronize-files-between-two-servers.html http://xmodulo.com/synchronize-files-between-two-servers.html
The rsync solution: rsync解决方案:
You will need to ssh into one of the servers first (this should be trivial). 您首先需要将ssh放入其中一台服务器(这应该很简单)。 Once in you can run this. 进入后即可运行此程序。
rsync -rtlzv --ignore-errors -e ssh . username@hostname:/path/to/directory
from: http://darcynorman.net/2009/01/07/how-i-move-stuff-between-servers-with-rsync/ 来自: http : //darcynorman.net/2009/01/07/how-i-move-stuff-between-servers-with-rsync/
The scp solution: scp解决方案:
I actually think this is the most elegant way because you do not have to ssh in first. 我实际上认为这是最优雅的方法,因为您不必先使用ssh。 Somethibng like this: 像这样的东西:
nohup scp alice@source:/the/answer/of/all bob@target.example.com:/var/tmp/42 &
from: https://unix.stackexchange.com/questions/65116/does-a-scp-transfer-close-when-i-close-the-shell 来自: https : //unix.stackexchange.com/questions/65116/does-a-scp-transfer-close-when-i-close-the-shell
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.