pip install winpexpect

expect写法

/usr/bin/expect <<-EOF
    set timeout 3000
    spawn ssh root@${server_ip}
    expect {
        "password:" { send "1234\n" }
        "root@" { send "ps aux | grep  \"pzx-3.0.0.jar --spring.profiles.active=${version}\" | awk '{print $2}' |xargs kill -9" }
        "root@" { send "cd ${java_path}" }
        "root@" { send "nohup  java -jar ${java_path}/pzx-3.0.0.jar --spring.profiles.active=${version} --pzxmq.consumer=true --pzx.myUtils.hostId=1  >/dev/null 2>&1 &" }
    }
    expect interact
EOF

虽然很帅的写法,然而并不如直接执行服务器脚本来的实在。

expect在bash中不能使用星号

目前还不知道如何转义,在上传文件的时候,很不方便。

/usr/bin/expect <<-EOF
    set timeout 3000
    spawn scp -r ${basepath}/pzx_vue2/dist_cn/ root@${server_ip}:${html_path}_cn
    expect "password:" {  send "1234\n" }
    expect interact
EOF

解决的方法是把 scp 写到另一个 #!/bin/expect 的文件。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-12
  • 2022-01-14
  • 2021-09-26
  • 2022-12-23
  • 2021-11-22
  • 2021-08-05
  • 2022-12-23
相关资源
相似解决方案