有什么方法可以读取 2 个文件中的以下值并执行 rsync 操作以从不同主机和 JVM 复制文件。
注意:我们有 2 个不同的主机,而 JVM 在这两个主机上是通用的,因为它们在集群中运行。
目前,我在 shell 脚本中有以下命令。但是,我想通过文件传递 Host_Name 和 JVM_Name 的值或通过文件读取。
例如
主机_1
rsync -hav -e ssh --info=progress2 user@loggerserver:/xxx/xxxx/host_name_1/logs/JVM_Name_1/logs/messages.log /cygdrive/d/xxx/xxxx/host_name_1/JVM_Name_1/messages.log
rsync -hav -e ssh --info=progress2 user@loggerserver:/xxx/xxxx/host_name_1/logs/JVM_Name_2/logs/messages.log /cygdrive/d/xxx/xxxx/host_name_1/JVM_Name_2/messages.log
rsync -hav -e ssh --info=progress2 user@loggerserver:/xxx/xxxx/host_name_1/logs/JVM_Name_3/logs/messages.log /cygdrive/d/xxx/xxxx/host_name_1/JVM_Name_3/messages.log
rsync -hav -e ssh --info=progress2 user@loggerserver:/xxx/xxxx/host_name_1/logs/JVM_Name_4/logs/messages.log /cygdrive/d/xxx/xxxx/host_name_1/JVM_Name_4/messages.log
主机_2
rsync -hav -e ssh --info=progress2 user@loggerserver:/xxx/xxxx/host_name_2/logs/JVM_Name_1/logs/messages.log /cygdrive/d/xxx/xxxx/host_name_2/JVM_Name_1/messages.log
rsync -hav -e ssh --info=progress2 user@loggerserver:/xxx/xxxx/host_name_2/logs/JVM_Name_2/logs/messages.log /cygdrive/d/xxx/xxxx/host_name_2/JVM_Name_2/messages.log
rsync -hav -e ssh --info=progress2 user@loggerserver:/xxx/xxxx/host_name_2/logs/JVM_Name_3/logs/messages.log /cygdrive/d/xxx/xxxx/host_name_2/JVM_Name_3/messages.log
rsync -hav -e ssh --info=progress2 user@loggerserver:/xxx/xxxx/host_name_2/logs/JVM_Name_4/logs/messages.log /cygdrive/d/xxx/xxxx/host_name_2/JVM_Name_4/messages.log
答案1
创建一个包含您想要的任何主机的主机文件hosts.txt
。然后运行:
for i in $(cat hosts.txt); do for j in {1..4}; do rsync -hav -e ssh
--info=progress2
user@loggerserver:/xxx/xxxx/$i/logs/JVM_Name_$j/logs/messages.log
/cygdrive/d/xxx/xxxx/$i/JVM_Name_$j/messages.log; done; done
您可以更改大括号中的数字以包含您想要的任何范围。