Linux下远程批量执行shell脚本
如果在一个集群环境下同时给多个相同系统的服务器安装软件操作起来也是相当麻烦的,如果能这些服务器的root密码都是一致的,可以通过下面这个脚本进行远程批量执行shell脚本。
boot.sh
#!/bin/bash SERVERS="192.168.180.128" PASSWORD=123456 BASE_SERVER=192.168.180.133 auto_ssh_copy_id() { expect -c "set timeout -1; spawn ssh-copy-id $1; expect { *(yes/no)* {send -- yes\r;exp_continue;} *assword:* {send -- $2\r;exp_continue;} eof {exit 0;} }"; } ssh_copy_id_to_all() { for SERVER in $SERVERS do auto_ssh_copy_id $SERVER $PASSWORD done } ssh_copy_id_to_all for SERVER in $SERVERS do scp install.sh root@$SERVER:/root ssh root@$SERVER /root/install.sh done
install.sh就是你想在远程服务器上执行的脚本。
注意:所有服务器需要安装expect。
教程地址:http://blog.zhengshuiguang.com/linux/bat-shell.html
欢迎转载!但请带上文章地址^^
评论已关闭