您的位置:首页 > 其它

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: