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
posted @ 2020-04-29 19:47  pkuimyy  阅读(176)  评论(0编辑  收藏  举报