您的位置:首页 > 运维架构 > Shell

Linux:从一台主机向多台主机发送命令的SHELL

2014-08-12 10:27 471 查看
命令格式:  tt  <group|key>  <command>

eg:   tt crmexe pwd

       tt crmexe 'find . -name "*.log"'

      tt crmexe 'find . -name "*.sh"|sh'

more tt

#!/bin/sh

if [ $# -lt 2 ];then 

echo "Please input ARGV key :

            tt <Group|ip> [p|P] <CMD>

               Group: crmexe webexe 

                  or IP:xxx.xxx.xxx.xxx

               CMD

               [p|P]:  add first 'ps -ef|grep -v grep '

"

exit 1

fi

#默认passwd

passwd="123"

if [ "$2" = "p"  -o "$2" = "P" ]

then 

    cmd="ps -ef|grep -v grep|grep $3"

else

    cmd=$2

fi

grep -w $1 ${HOME}/sbin/data.dat|while read  grp name l_passwd

do

    if [ -z "$grp$name" ]

    then

        echo $1

        continue

    fi

    if [ -z $l_passwd ]

        then

        l_passwd=$passwd

    fi

    echo "------------------------ GROUP:$grp  Name: $name ------------------------"

    ${HOME}/sbin/sshpass -p $l_passwd ssh -n $name -o StrictHostKeyChecking=no $cmd
done

 data.dat 配置文件 :

crmexe crm@192.168.168.11

crmexe crm@192.168.168.12

webexe crm@192.168.168.13  456
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux command shell ssh