在需要对集群中的每台机器进行操作时,每次用ssh登录完成操作后退出,这样的操作很麻烦,而且如果集群数量过大将会是一件很浪费时间的任务。通过用ssh本机上使用shell脚本处理将会方便很多。
#!/bin/bash
ssh username@10.3.1.177 > /dev/null 2>&1 << eeooff
mkdir test
cd test
touch newfile
exit
eeooff
echo done!
除了在脚本中执行批量的远程命令之外,在终端也可以使用ssh命令完成相同的操作。
ssh username@10.3.1.177 "mkdir test ; cd test ; touch newfile "