批量ssh执行命令
2016-01-15 14:23
405 查看
[root@openfire1 script]# cat test.sh
#!/bin/bash
#本地通过ssh执行远程服务器的脚本
for ip in `cat iplist`
do
echo $1
if [[ -z $1 ]]; then #"-z",如果为空
echo "Not find command."
break
else
echo "$ip----------------------"
ssh $ip $1
fi
done
-------------------------------------------------------------------------
-------------------------------------------------------------------------
[root@openfire1 script]# cat test.sh
#!/bin/bash
#变量定义
ip_array=("172.16.100.23" "172.16.100.24" "172.16.100.25" "172.16.100.26" "172.16.100.27")
user="root"
remote_cmd=date
#本地通过ssh执行远程服务器的命令
for ip in ${ip_array[*]}
do
if [ $ip = "192.168.1.1" ]; then
port="7777"
else
port="22"
fi
ssh -t -p $port $user@$ip $1
echo done!
done
#!/bin/bash
#本地通过ssh执行远程服务器的脚本
for ip in `cat iplist`
do
echo $1
if [[ -z $1 ]]; then #"-z",如果为空
echo "Not find command."
break
else
echo "$ip----------------------"
ssh $ip $1
fi
done
-------------------------------------------------------------------------
-------------------------------------------------------------------------
[root@openfire1 script]# cat test.sh
#!/bin/bash
#变量定义
ip_array=("172.16.100.23" "172.16.100.24" "172.16.100.25" "172.16.100.26" "172.16.100.27")
user="root"
remote_cmd=date
#本地通过ssh执行远程服务器的命令
for ip in ${ip_array[*]}
do
if [ $ip = "192.168.1.1" ]; then
port="7777"
else
port="22"
fi
ssh -t -p $port $user@$ip $1
echo done!
done
相关文章推荐
- 职业生涯管理系统 servlet+javabean+mysql(三)登陆的实现
- 菜鸟之路-浅谈设计模式之原型模式
- NSMutableAttributedString,图文混排,字号变换,颜色变换
- 第一章 rsyslog整体架构
- error:LNK2005 已经在*.obj中定义
- 非对称加密算法-DH算法
- 模版字符串实例:模板编译
- zabbix使用外部邮箱账号发送报警邮件设置
- 机器学习与数据挖掘网上资源搜罗
- Mybatis 中在传参时,$ 和# 的区别
- js-Event构造函数,也许你需要
- .net 连接sqlserver类库
- POJ2182(排队问题)
- 深入理解Android View
- 【转】python数据格式化之pprint
- iOS开发之添加自定义字体
- 内存错误
- iOS What The Fuck UITableView
- iOS8 以上版本的定位问题
- H3C S5120交换机OID