expext

expect自动登录以及远程脚本执行

♀尐吖头ヾ 提交于 2019-12-02 03:09:23
0、前言 场景描述:现有192.168.5.51~192.168.5.55需要发布不同观点项目,希望达到的效果是ssh登录到192.168.5.117执行一个脚本一键发布所有项目到51,52,53,54,55. 1、remote.sh 此脚本放置在本地终端 #!/bin/sh /usr/bin/expect <<EOF #!/usr/bin/expect if { "$1" == "174" } { set timeout -1 spawn /usr/local/nginx/sbin/remote1.sh expect { "Are you sure you want to continue connecting (yes/no)?" {send "yes\r";exp_continue;} "root@192.168.5.174's password:" {send "passowrd\r";exp_continue;} } } if { "$1" == "soa-55" } { spawn /usr/local/nginx/sbin/remote_soa_55.sh expect { "Are you sure you want to continue connecting (yes/no)?" {send "yes\r";exp_continue;} "root@192