执行expect报错


2.查看expect的路径,可以用

[zhuying@SOR_SYS opt]$ which expect 

/usr/bin/expect

[zhuying@SOR_SYS opt]$ view autosu.sh

3。确定脚本有可执行权限

chmod +x autosu.sh

#!/usr/bin/expect  -f            //这个expect的路径就是用which expect 查看的结果

spawn su - Oracle             //切换用户
expect "password:"           //提示让输入密码
send "99billzy\r"       //输入oracle的密码
interact                             //操作完成

这在root用户切换到oracle用户的时候特别的快,但是在其他用户切换到oracle的时候则需要等待一段时间!

另外需要注意的是:

不能按照习惯来用sh autosu.sh来这行expect的程序,会提示找不到命令,如下:

autosu.sh: line 3: spawn: command not found
couldn't read file "password:": no such file or directory
autosu.sh: line 5: send: command not found
autosu.sh: line 6: interact: command not found

因为expect用的不是bash所以会报错。执行的时候直接./autosu.sh就可以了。~切记!


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM