將某文件遠程拷貝到指定ip機器上的指定目錄下:
java
./scp_file.sh /tmp/xx.sh /tmp/test/linux
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支持)(可帶參數):shell
./execute.sh /tmp/xx.sh xxbash
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 app
#!/bin/bash cp /opt/tmp/hosts.txt /opt/tmp/hosts.txt.bak echo "$? copy finish!" exit 0
append-ssh.sh ssh
#!/bin/bash cat /opt/tmp/ssh.txt >> /root/.ssh/authorized_keys echo "$? append ssh finish!" exit 0
rmtest.shide
#!/bin/bash rm -rf $1 echo "$? rm finish!" exit 0
install-hadoop-hbase.sh oop
#!/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 spa
#!/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 ip
#!/bin/bash ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa echo "$? set ssh keygen finish!" exit 0