侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

无敌服务器交互脚本

2023-12-18 星期一 / 0 评论 / 0 点赞 / 120 阅读 / 1531 字

☆注意要执行的操作放在注释那行的下面 用send包起来☆ 本例中是进入指定目录,开始一个程序。 #!/usr/bin/expect ##author:stevenrao##打开 ssh 终端,省去密码

注意要执行的操作放在注释那行的下面 用send包起来

本例中是进入指定目录,开始一个程序。

#!/usr/bin/expect ##author:stevenrao##打开 ssh 终端,省去密码交互脚本  if { $argc==0 } {send "usage: $argv0 ip /[port/]/n";exit}#要打开的远程机器ip 端口set ip [lindex $argv 0]set port 22if { $argc==2 } {set port [lindex $argv 1]} #日志文件,一ip为文件名log_file $iplog_user 1 #用户名密码set user rootset password cwvbu3knna #启动ssh登录进程spawn /usr/bin/ssh -p $port $user@${ip}set myid $spawn_idset timeout 10  while { [string length $myid] } { #提示符set prompt "(%|#|//$|>|//])"catch {set prompt $env(EXPECT_PROMPT)} expect {   "*tcsetattr failed*" {    send_log "/n${ip},sshsyscallerror/n";    break    }   "*Authentication failed*" {    break    }   "*yes/no*" {    send "yes/n"    }    "*password: " {    send "$password/n"    }    timeout {        send_log "/n${ip},logintimeout/n"        exit        }      -re $prompt {    set timeout 1    send_log "/n${ip},loginsuccess/n"    ##登录成功,这里放你想要执行的交互脚本    send "cd /usr/local/court/jusspider-1.0-RELEASE/bin/n"    send "sh start.sh/n"    send "exit/n"    interact;exit    expect eof {        send_log "eof/n"        exit        }    }    }}

就这样,祝大家套用成功^_^

广告 广告

评论区