expect 普通用户自动输入密码到root下,执行命令
生活随笔
收集整理的這篇文章主要介紹了
expect 普通用户自动输入密码到root下,执行命令
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
案例:當前服務器取消了直接使用root登錄服務器,只能使用普通用戶先登錄,然后再su - root 執行root下的命令。
shell腳本如下:
#!/usr/bin/expect -f
set password {root_password}
spawn su - root
expect "密碼:"
send "$password\r"
#send "sh ceshi.sh > temp.log &\r"
#send "timeout 120 tail -f temp.log\r"
send "pwd\r"
send "exit\r"
interact
exit 0
轉載于:https://blog.51cto.com/10921657/2118938
總結
以上是生活随笔為你收集整理的expect 普通用户自动输入密码到root下,执行命令的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: spark on yarn 配置及异常解
- 下一篇: React 教程第六篇 —— 样式绑定