案例: 当前服务器取消了直接使用 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
来源: http://www.bubuko.com/infodetail-2611824.html