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

来源:互联网 发布:u盘0字节怎么找回数据 编辑:程序博客网 时间:2024/04/30 00:54

命令格式:  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


0 0
原创粉丝点击