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"
interactexit 0
原文:http://blog.51cto.com/10921657/2118938