執行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