脚本可以直接使用.sh的文件【使用的是tp】,
脚本文件的格式
set timeout 10【设置超时时间,如果超过时间没有expect出现,则退出!设置永不超时使用----set timeout -1】
spawn su root 【使用root用户】
expect “:” 【设置密码】
send “密码” 【密码内容】
send “cd /home/wwwroot/test/\r” 【进入相应的文件】
send “php think LM test\r” 【执行相应的命令】
send “php think LM test2\r”
send “cd /home/wwwroot/api/\r”
send “php think LM api\r”
send “php think LM api2\r”
expect eof 【与spawn对应表示捕获终端输出信息终止,一定要加,expect脚本必须以interact或expect eof结束,执行自动化任务通常expect eof就够了。】
exit