第一个expect脚本
时间:2010-06-03 来源:net_liufeng
昨天23:20,在73上开始搞expect,起因是彩票系统需要每天发布两次,偶不想手工做,可这个发布脚本偏偏是menu形式的,必须要有交互才行,于是开始搞expect,73上测试了chsh没有问题,在发布机上部署的时候,发现没有expect包,系统还是64位的,晕,于是强制卸载tcl,然后yum install expect,一切顺利,不过弄完以后,脑袋及其兴奋,搞的晚上失眠了,郁闷,现在头很沉沉的。
上午来了以后把这个expect部署上去了,长下面这样,其实这里面最不好搞的是他的正则,我man了一下学着例子做了几个(.*)才搞定,还好了,不用每天手工做了,expect初体验,还行吧。
#! /usr/bin/expect
spawn /bin/sh /home/lottery/fabu/menu.sh
expect -re "Your(.*)choice(.*)2(.*)Q](.*)\n" send "3\n"
expect -re "hit any key to return(.*)\n" send "first\n"
expect -re "Your(.*)choice(.*)2(.*)Q](.*)\n" send "4\n"
expect -re "hit any key to return(.*)\n" send "second\n"
expect -re "Your(.*)choice(.*)2(.*)Q](.*)\n" send "q\n"
expect eof
exit
#! /usr/bin/expect
spawn /bin/sh /home/lottery/fabu/menu.sh
expect -re "Your(.*)choice(.*)2(.*)Q](.*)\n" send "3\n"
expect -re "hit any key to return(.*)\n" send "first\n"
expect -re "Your(.*)choice(.*)2(.*)Q](.*)\n" send "4\n"
expect -re "hit any key to return(.*)\n" send "second\n"
expect -re "Your(.*)choice(.*)2(.*)Q](.*)\n" send "q\n"
expect eof
exit
相关阅读 更多 +