linux ssh -l 命令运用
2016-04-10 20:48
316 查看
ssh是远程登录命令,-l选项是最常用的选项,下面是我的一些总结
远程登录:ssh -l userName ip
执行远程命令(不登录):ssh -l userName ip command
更多的情况是,command处为一个shell脚本,而配合expect spawn 一起使用,效果是最好的,比如下面这段shell脚本是实现同时刷新两个ip主机的redis缓存的:
上面例子中的 /home/weihu/bin/flushall_redis.sh 即为各自主机上面需要执行shell文件(用于刷新各自主机redis缓存的)。例子中的重点就是exe函数、以及ssh -l 两部分。
远程登录:ssh -l userName ip
# 远程登录到 10.175.23.9
ssh -l root2 10.175.23.9
执行远程命令(不登录):ssh -l userName ip command
# 不远程登录到 10.175.23.9,但通过命令查看10.175.23.9上面的nginx的进程情况
ssh -l root2 10.175.23.9 ps -ef|grep nginx
更多的情况是,command处为一个shell脚本,而配合expect spawn 一起使用,效果是最好的,比如下面这段shell脚本是实现同时刷新两个ip主机的redis缓存的:
#!/bin/sh echo "--------------------flushall_all_redis init--------------------" Server09=("root1" "root1_pwd") Server10=("root2" "root2_pwd") function exe() { expect -c " $1 set timeout 300 expect { \"*(yes/no)?\" { send \"yes\n\" expect \"*assword:\" { send \"$2\n\" } } \"*password:\" { send \"$2\n\" } } expect eof " } echo "" echo "--------------------start reflush redis from 10.175.23.9--------------------" exe "spawn ssh -l ${Server09[0]} 10.175.23.9 \"/home/weihu/bin/flushall_redis.sh\"" "${Server09[1]}" echo "" echo "--------------------start reflush redis from 10.175.23.10--------------------" exe "spawn ssh -l ${Server10[0]} 10.175.23.10 \"/home/weihu/bin/flushall_redis.sh\"" "${Server10[1]}"
上面例子中的 /home/weihu/bin/flushall_redis.sh 即为各自主机上面需要执行shell文件(用于刷新各自主机redis缓存的)。例子中的重点就是exe函数、以及ssh -l 两部分。
相关文章推荐
- Centos7 Ansible安装
- CentOS 6的系统启动流程
- lab7:Linux内核如何装载和启动一个可执行程序
- Linux学习(3)——文件管理命令
- 十款最常见的Linux发行版
- 苹果后门、微软垄断与Linux缺位
- Linux 下編輯 PDF 檔的工具
- Linux内核分析——可执行程序的装载
- vnc服务器的搭建
- NUll
- centos mysql更改数据存放位置datadir(NTF格式硬盘)
- Linux命令整合之alias
- Linux内核如何装载和启动一个可执行程序
- Linux中用户,组及权限的概念及相关命令
- Google Nexus5在linux下刷原生安卓 android6.0
- CentOS下使用yum搭建LAMP环境
- archlinux xfce4 l2tp服务启动失败
- linux小包集合
- 在Linux中布Java项目的开发环境
- GCC & ELF文件格式 &linux内核如何加载和启动一个可执行程序