简体   繁体   English

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

[英]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.

相关问题 Python 脚本将文件和目录从一台远程服务器复制到另一台远程服务器 - Python script to copy file and directory from one remote server to another remote server Python PySFTP将文件从一台远程服务器传输到另一台远程服务器 - Python PySFTP transfer files from one remote server to another remote server 在远程节点执行 bash 脚本并从服务器通过 python 控制 - Execute bash script at remote node and controlled via python from server Python脚本将数据从一台MySQL服务器传输到另一台MySQL服务器 - Python script to transfer data from one MySQL server to another one 使用 python 在远程服务器上运行 bash 脚本 - Run bash script on remote server using python 如何从Windows系统将文件从python脚本复制到任何其他远程服务器? - How do I copy files from windows system to any other remote server from python script? 我需要编写一个 python 脚本,它将建立从一台服务器(server1)到另一台远程服务器(server2)的无密码连接 - I need to write a python script which will make a passwordless connection from one server (server1) to another remote server(server2) 使用python将文件从本地计算机传输到远程Windows服务器 - Transfer file from local machine to remote windows server using python 将数据库从一台服务器复制到另一台服务器,并在数据库事件上触发python脚本 - Copy database from one server to another server + trigger python script on a database event 将数据从PHP(客户端)传输到Python脚本(服务器) - Transfer data from PHP(client) to a Python script(server)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM