需要在多台服务器上执行同样的脚本,记录下此方法。
ssh user@hostname -C "/bin/bash" < test.sh
脚本带参数怎么办?
[root@ ~]# cat local.sh printf 'Argument is __%s__\n' "$@"[root@ ~]# ssh user@hostname 'cat| bash /dev/stdin arg1 arg2 arg3' < local.sh Argument is __arg1__Argument is __arg2__Argument is __arg3__
参考:
另附上一个自己用的更改centos6.x repo源为阿里云源的脚本
#!/bin/bash##usage : change repo to ailiyun#author : firxiao##centos6.x####CentOS-Base.repo##function centos6(){mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backupwget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo}##epel.repo##function epel(){mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backupmv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backupwget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo}if [ ! -x "/usr/bin/wget" ];then{yum install wget -y && centos6 && epel}else{centos6 && epel}fi