上传脚本到服务器命令
I frequently run some commands/scripts on a batch of servers whose IPs are already collected in a file. I usually use a simple loop and call the ssh
to run these commands remotely and automatically. This operation, however, is common and can be abstracted into a separate script.
我经常在一批IP已经收集在文件中的服务器上运行一些命令/脚本。 我通常使用一个简单的循环并调用ssh
来远程自动运行这些命令。 但是,此操作很常见,可以抽象为单独的脚本 。
Here is the script that I come up with for running commands automatically on a batch of servers:
这是我用来在一批服务器上自动运行命令的脚本:
The usage:
用法:
usage: ./batch-cmd.sh file cmd
Each host in one line in the file
The mechanism is to use ssh
to run a command remotely. For example, to run command “ls” on remote host $host
, we just run
机制是使用ssh
远程运行命令 。 例如,要在远程主机$host
上运行命令“ ls”,我们只需运行
ssh $host "ls"
If the current user can log on $host
without password, it is automatically executed.
如果当前用户可以不用密码登录$host
,它将自动执行。
翻译自: https://www.systutorials.com/script-running-commands-on-a-list-of-servers/
上传脚本到服务器命令