我已经在 bash 中完成了简单的脚本 - 该脚本应该将具有特定新名称的文件从服务器 1 传输到远程服务器 2。
有人可以帮忙解决这个问题并将所有脚本传输到 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
最佳答案
对此有多种解决方案。
一个选项是一致的:
http://xmodulo.com/synchronize-files-between-two-servers.html
rsync 解决方案:
您需要首先通过 ssh 连接到其中一台服务器(这应该很简单)。一旦进入,您就可以运行它。
rsync -rtlzv --ignore-errors -e ssh . username@hostname:/path/to/directory
来自:http://darcynorman.net/2009/01/07/how-i-move-stuff-between-servers-with-rsync/
scp 解决方案:
我实际上认为这是最优雅的方式,因为您不必先通过 ssh 登录。像这样的东西:
nohup scp alice@source:/the/answer/of/all bob@target.example.com:/var/tmp/42 &
来自:https://unix.stackexchange.com/questions/65116/does-a-scp-transfer-close-when-i-close-the-shell
关于python - Bash 脚本传输到 Python - 将日志从服务器复制到另一个远程服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26105794/