在运维或在日常工作生活中,我们经常会把一个文件拷贝到其它服务器上,或同时分发到多个服务器上,甚至要求目标机将文件放在相同的路径下,方便程序进一步调用。
Linux文件分发脚本,只需一条命令将你的文件分发到各个服务器上
遇到这种问题,我们通常的做法是使用scp或rsync命令把文件拷贝一个一个地拷贝到多台服务器上,这样做费事费力;大神的做法是使用ansible的playbook一下把事情干完,前提是你得会ansible;快捷的做法就是使用今天的脚本了。
效果演示
目前拥有4台机器,分别为client、node1、node2和node3,client与其它3台机器能够建立ssh链接。在client的/root/test目录下有a.txt和b.txt两个文件。
Linux文件分发脚本,只需一条命令将你的文件分发到各个服务器上
[root@client test]# ls /root/test/
a.txt b.txt
[root@client test]#
我把文件分发到node1、node2和node3的/root/test下,执行以下命令:
# 在/root/test目录下执行, xrsync是我的脚本
[root@client test]# xrsync a.txt b.txt
执行分发过程:
[root@client test]# xrsync a.txt b.txt
============ node1 ============
sending incremental file list
a.txt
sent 93 bytes received 35 bytes 256.00 bytes/sec
total size is 2 speedup is 0.02
sending incremental file list
b.txt
sent 93 bytes received 35 bytes 85.33 bytes/sec
total size is 2 speedup is 0.02
============ node2 ============
sending incremental file list
a.txt
sent 93 bytes received 35 bytes 256.00 bytes/sec
total size is 2 speedup is 0.02
sending incremental file list
b.txt
sent 93 bytes received 35 bytes 256.00 bytes/sec
total size is 2 speedup is 0.02
============ node3 ============
sending incremental file list
a.txt
sent 93 bytes received 35 bytes 85.33 bytes/sec
total size is 2 speedup is 0.02
sending incremental file list
b.txt
sent 93 bytes received 35 bytes 256.00 bytes/sec
total size is 2 spee
Linux文件分发脚本 只要一条命令将你的文件分发到各个服务器上
在运维或在日常工作生活中,我们经常会把一个文件拷贝到其它服务器上,或同时分发到多个服务器上,甚至要求目标机将文件放在相同的路径下,方便程序进一步调用。 Linux文件分发脚本,只需一条命令将你的文件分发到各个服务器上 遇到这种问题,我们通常的做
本文来自网络,不代表站长网立场,转载请注明出处:https://www.tzzz.com.cn/html/server/linux/2021/1201/31973.html