首页 > 其他 > 详细

expect 普通用户自动输入密码到root下,执行命令

时间:2018-05-22 10:33:27      阅读:388      评论:0      收藏:0      [点我收藏+]
案例:当前服务器取消了直接使用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

expect 普通用户自动输入密码到root下,执行命令

原文:http://blog.51cto.com/10921657/2118938

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!