码迷,mamicode.com
首页 > 系统相关 > 详细

一个有用的shell脚本

时间:2016-09-30 00:49:45      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:

#!/bin/bash

#if [ $1 -eq null ]; then 
#   echo "please input params1!"
#   exit
#fi

#if [ $2 -eq null ]; then 
#   echo "please input params2!"
#   exit
#fi

# type , $1 { scp, ssh },  src $2, dst $3
user=hadoop

if [ "$3" != "" -a "$1" != "scp" ] ; then
    user=$3
fi

if [ "$4" != "" ] ; then 
    iplist=$4
else 
    iplist=`cat /home/hadoop/gitclone/opshell/hadoop/machine.conf` 
fi

for ip in $iplist;do
   echo "-----ops $ip -------------"
   if [ "$1" == "scp" ] ; then    
       scp -r $2 $user@$ip:$3
   elif [ "$1" == "ssh" ] ; then
    ssh $user@$ip "mkdir ~/.ssh | touch ~/.ssh/authorized_keys"
    cat ~/.ssh/id_rsa.pub | ssh $user@$ip "cat >> ~/.ssh/authorized_keys"
    ssh $user@$ip "chmod 700 ~/.ssh"
   elif [ "$1" == "cmd" ] ; then
    ssh $user@$ip "$2"
   fi
done

 

一个有用的shell脚本

标签:

原文地址:http://www.cnblogs.com/luolizhi/p/5921583.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!