python - Bash 脚本传输到 Python - 将日志从服务器复制到另一个远程服务器

标签 python linux bash shell

我已经在 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/

相关文章:

python - 在 pandas.DataFrame 中插入零到缺失数据

python - 仅打印所需的列

linux - 为什么内核映射到与进程相同的地址空间?

linux - 使用 9 位序列号对文件进行排序和重命名

python - 如何提高python中虚线线图的效率(速度)

列表中的 Python 函数

linux - 如何在 gnu screen 中绑定(bind)多个键,特别是使用箭头键

linux - 如何更改Linux内核名称

bash gnu 并行帮助

linux - 如何从 awk 语句添加时间格式 hh :mm. ss