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
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主机的执行相同的命令
- Linux下shell脚本PING命令只要延迟高于100ms就发送个邮件
- 批量修改LINUX主机密码 和发送命令
- Linux 命令 - ping: 向网络主机发送 ICMP ECHO_REQUEST 包
- C语言中 使用popen函数向linux系统发送shell命令
- linux教程,Shell命令大全
- linux主机下载命令
- 深入浅出Shell 编程:Unix/Linux 命令
- [linux.admin.shell] find命令常用法
- linux 系统命令----修改主机名
- Linux常用shell命令
- linux发送邮件的shell脚本
- 使用Linux操作系统命令来发送信息
- Linux小白教程:vi(shell文本编辑器)保存、退出命令
- Linux的shell命令的学习
- Linux Bash Shell学习(四):编辑命令
- Linux:shell中的管道命令
- Linux学习笔记-shell命令[转帖]
- 写得蛮好的linux学习笔记(压缩命令,vi一般用法,认识SHELL,正规表示法)
- Linux主要shell命令详解