expect安装以及进程查杀重启

来源:互联网 发布:djay pro 破解版 mac 编辑:程序博客网 时间:2024/06/01 20:39

进程部分参考:http://blog.csdn.net/yuanxuran0101/article/details/5548205

需求是这样:需要远程交互linux,重启一个程序

首先是expect安装:

  892  tar -zxvf tcl8.4.20-src.tar.gz 
  893  cd tcl8.4.20
  894  cd unix/
  895  ./configure
  896  make && make install
  897  cd ../../
  898  ll
  
  
  899   tar -zxvf expect5.45.3.tar.gz 
  900  cd expect5.45.3
  902  ./configure --with-tclinclude=/data01/tool/encrypt/tcl8.4.20/generic --with-tclconfig=/usr/local/lib/
  903  make && make install
  904  expect
  896  ln -s /usr/local/bin/expect /usr/bin/expect

然后是进程查杀和重启

#!/usr/bin/expect  
set server_name [lindex $argv 0]
spawn ssh root@100.100.114.185
expect {
#"yes/no" { send "yes\n";exp_continue }
"password" { send "123456\n" }
}
expect "]#" 
send {kill `ps -ef | grep encrypt-decrypt-1.0.0_v1026.jar | grep -v grep | awk '{print $2}'`}
send "\n"
expect "]#" 
send {echo program has bean killed}
send "\n"
expect "]#" 
sleep 3
send {setsid java -jar encrypt-decrypt-1.0.0_v1026.jar}
send "\n"
expect eof 

原创粉丝点击