将某文件远程拷贝到指定ip机器上的指定目录下:
./scp_file.sh /tmp/xx.sh /tmp/test/
echo "将文件 $1 拷贝到 $2 目录下!" for ip in 192.168.60.243 192.168.60.244 192.168.60.245 192.168.60.246 192.168.60.248 do scp -r $1 root@$ip:$2 echo "scp $1 to $ip is : $? " done echo "$? 分发完毕!!"
远程执行指定ip机器上的指定shell文件命令(需要ssh支持)(可带参数):
./execute.sh /tmp/xx.sh xx
for ip in 192.168.60.243 192.168.60.244 192.168.60.245 192.168.60.246 192.168.60.248 do ssh root@$ip $1 $2 echo "execute $1 $2 at $ip is : $? " done echo "$? $1执行完毕!"
copy-hosts.sh
#!/bin/bash cp /opt/tmp/hosts.txt /opt/tmp/hosts.txt.bak echo "$? copy finish!" exit 0
append-ssh.sh
#!/bin/bash cat /opt/tmp/ssh.txt >> /root/.ssh/authorized_keys echo "$? append ssh finish!" exit 0
rmtest.sh
#!/bin/bash rm -rf $1 echo "$? rm finish!" exit 0
install-hadoop-hbase.sh
#!/bin/bash cp /opt/tmp/hadoop-2.5.1.tar.gz /opt/hadoop-2.5.1.tar.gz cp /opt/tmp/hbase-0.98.7-hadoop2-bin.tar.gz /opt/hbase-0.98.7-hadoop2-bin.tar.gz echo "$? copy finish!" cd /opt/ tar xvf hbase-0.98.7-hadoop2-bin.tar.gz echo "$? install hbase finish!" tar xvf hadoop-2.5.1.tar.gz echo "$? install hadoop finish!" exit 0
install-jdk.sh
#!/bin/bash mkdir -p /usr/java/ cp /opt/tmp/jdk-6u45-linux-x64.bin /usr/java/jdk-6u45-linux-x64.bin echo "$? copy finish!" cd /usr/java/ sh /usr/java/jdk-6u45-linux-x64.bin echo "$? install jdk finish!" exit 0
set-keygen.sh
#!/bin/bash ssh-keygen -t dsa -P ‘‘ -f ~/.ssh/id_dsa echo "$? set ssh keygen finish!" exit 0
原文地址:http://zlfwmm.blog.51cto.com/5892198/1859264