通过选择从一台服务器到另一台服务器的Shell脚本

时间:2018-11-05 16:26:52

标签: shell scp

如何将文件从一台服务器复制到另一台服务器?我有3台服务器,必须从中选择将文件从一台服务器复制到另一台服务器。我知道scp是要使用的命令,但我只是想知道如何编写Shell脚本,该脚本使我可以选择将文件从一台服务器复制到另一台服务。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

我会写一个脚本,

  1. 具有三个服务器的静态定义列表。

list_of_things=(one two three)

  1. 将本地计算机上的文件/文件路径作为输入/参数

first_argument=$0 second_argument=$1

  1. 检查文件是否存在

if [ -e first_argument ]

  1. 浏览服务器列表,并使用scp将文件传输到每个服务器。

for item IN list_of_things; do // do something here then

通读bash脚本教程以获取更多指导:https://ryanstutorials.net/bash-scripting-tutorial/