centos系统的直接yum下载即可


交互式自动输入mysql密码

#!/usr/bin/expect
解释器声明 set timeout 30 设置超时时间,单位秒 spawn mysql -uroot -p spawn 是expect的内部命令,个人理解其作用就是宣告进入人机模拟开始 expect "Enter password:"
expect也是内部命令,作用是监视终端输出是否包含后面的内容,有则执行下面的send,没有就等待上面设置的timeout时间 send "123456\r"
这个就是执行交互动作了,模拟人手动输入的东东,切记最后要带上回车符“\r” interact
留在终端中,不加会在spawn的位置退出


脚本: #!/usr/bin/expect
set timeout 30
spawn mysql -uroot -p
expect "Enter password:"
send "123456\r"
interact


执行命令:expect test.sh