如下腳本的大前提是用root 創建的無密鑰鏈接 bash
#!/bin/bash . /etc/init.d/functions if [ $# -ne 1 ];then echo "USAGE:/bin/sh $0 ARG1" exit 1 fi for n in 144 145 146 do echo ++++++10.0.137.$n +++++++++++++++++ ssh 10.0.137.$n $1 if [ $? -eq 0 ];then action "10.0.137.$n" /bin/true else action "10.0.137.$n" /bin/false fi done
#!/bin/sh . /etc/init.d/functions file="$1" remote_dir="$2" if [ $# -ne 2 ];then echo "usage:$0 argv1 argv2" echo "must have two argvs." exit fi for ip in $(cat /service/scripts/ip.txt) do scp -P22 -r -p $file root@$ip:~ >/dev/null 2>&1 &&\ ssh -p 22 -t root@$ip sudo rsync -avz -P $file $remote_dir >/dev/null 2>&1 if [ $? -eq 0 ];then action "$ip is successful." /bin/true else action "$ip is failure." /bin/false fi done
#!/bin/bash . /etc/init.d/functions for n in 144 145 146 do scp -P22 /etc/hosts root@10.0.137.$n:~ >/dev/null 2>&1 &&\ ssh -t root@10.0.137.$n sudo rsync ~/hosts /tmp/tt.$(date +%F) >/dev/null 2>&1 &&\ if [ $? -eq 0 ];then action "10.0.137.$n" /bin/true else action "10.0.137.$n" /bin/false fi done