expect 实现模拟交互

expect 实现模拟交互

expect安装

apt install expect

server

#! /bin/bash
read -p "username: " username
read -sp "password: " password
echo -en "\n" # echo 
echo $username, $password

client

#! /usr/bin/expect
spawn ./server.sh
expect "username: "
send "foo\n"
expect "password: "
send "bar\n"
interact

运行方法

./client.sh
上一篇:解决ssh登录后闲置时间过长而断开连接


下一篇:ubuntu使用ssh远程登陆操作ubuntu