ssh登录脚本 expect语言中使用awk
2010-05-01 10:55
537 查看
五一劳动节被叫过去加班,要升级程序,有100多台的服务器。
需要先登录服务器,再将服务器上的程序停掉,服务器上的程序进程是用screen建立的,ps -ef 他的进程PID 然后kill掉
#!/usr/bin/expect
set ipaddr [lindex $argv 0]
spawn ssh ict@$ipaddr
expect "yes/no)?"
sleep 3
send "yes/r"
expect "password:"
sleep 6
send "123ic#/r"
expect "]$"
send {kill -9 `ps -ef | grep SCREEN | grep -v pts | awk '{print $2}'`}
send "/r"
expect "]$"
send "screen -wipe/r"
expect "]$"
send "exit"
expect eof
exit
循环所有节点ip
#!/bin/bash
cat redhat_client_ip.txt | while read line; do
echo "$line"
./kill_process.sh $line >$line.log
done
需要先登录服务器,再将服务器上的程序停掉,服务器上的程序进程是用screen建立的,ps -ef 他的进程PID 然后kill掉
#!/usr/bin/expect
set ipaddr [lindex $argv 0]
spawn ssh ict@$ipaddr
expect "yes/no)?"
sleep 3
send "yes/r"
expect "password:"
sleep 6
send "123ic#/r"
expect "]$"
send {kill -9 `ps -ef | grep SCREEN | grep -v pts | awk '{print $2}'`}
send "/r"
expect "]$"
send "screen -wipe/r"
expect "]$"
send "exit"
expect eof
exit
循环所有节点ip
#!/bin/bash
cat redhat_client_ip.txt | while read line; do
echo "$line"
./kill_process.sh $line >$line.log
done
相关文章推荐
- expect使用ssh登录脚本
- ssh expect自动登录的脚本代码
- 使用expect工具ssh登录远程服务器并执行命令操作
- SSH使用expect实现密码交互脚本
- 使用shell脚本自定义实现选择登录ssh
- python 脚本实现ssh登录--expect 和 pxssh
- 使用expect实现ssh不输入密码登录远程服务器
- shell脚本无密码登录 expect使用
- expect 提供用户名和密码的SSH自动登录脚本
- Linux使用expect脚本实现远程机器自动登录
- awk 系列:如何使用 awk 语言编写脚本
- 使用expect和ssh远程执行命令的脚本
- 实现真正的自动化,expect脚本语言使用
- Linux使用expect实现自动登录的脚本
- 使用expect实现自动交互,自动登录脚本
- expect解决ssh无法使用shell直接登录的问题
- 使用ssh登录shell脚本远程调用
- 使用expect实现shell脚本中scp,ssh自动输入口令