批量ssh执行命令
2024-09-30 22:39:31
[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
最新文章
- Oracle 中 sys和system帐号的区别
- hdu 3966 Aragorn's Story 树链剖分 按点
- 【水题】NOIP201504推销员
- shell(1)
- 真正的inotify+rsync实时同步 彻底告别同步慢
- JAVA中LOCK
- Lustre文件系统测试——obdfilter-survey测试
- Linux基础一
- freemark标签中输出boolean值
- shell 查找与替换
- springMVC 多文件上传前后台demo
- 3G设置linux路由-iptables配置
- leetcode-53.最大子序和
- Iroha and a Grid AtCoder - 1974(思维水题)
- spring boot集成ehcache 2.x 用于hibernate二级缓存
- System.exit(int status)
- JSP页面与JSP页面之间传输参数出现中文乱码的解决方案
- 第134天:移动web开发的一些总结(二)
- 2018 ICPC北京 H ac自动机
- POJ 1041 John&;#39;s trip Euler欧拉回路判定和求回路
热门文章
- JAVA环境变量配置后未变动配置失效处理
- (转) 淘淘商城系列——Redis的安装
- 导出数据到Excel表格
- ThinkPHP---框架介绍
- 16 this和super和构造代码块
- java.net.MalformedURLException: no protocol: www.baidu.com
- java面试题链接
- 透彻分析C/C++中memset函数
- exception对象的使用及常用方法
- Centos下Yum安装PHP5.5,5.6,7.0及扩展