使用expect脚本登录到root账号并执行命令
2011-04-20 10:22
435 查看
通过expect脚本登录root账号,方法比较简单,只要先写一个如下格式的脚本即可:
参考:
http://freebsder.blog.163.com/blog/static/1041573201021510155036/ http://www.examda.com/linux/fudao/20100728/102721675.html
#!/usr/bin/expect set timeout=5 #设置5秒超时 spawn sudo su expect "*assword*" send "123456\r" #发送密码,别忘了以\r结尾 expect "*#*" #等待#提示符的出现 send "ls -l>/tmp/1\r" expect "*#*" send "uname -a>/tmp/2\r" #interact #使用interact后,脚本将退出到root账号下,可以手动执行root权限的命令 expect eof exit
参考:
http://freebsder.blog.163.com/blog/static/1041573201021510155036/ http://www.examda.com/linux/fudao/20100728/102721675.html
相关文章推荐
- 20.27分发系统介绍;20.28expect脚本远程登录;20.29expect脚本远程执行命令;20.30expect脚本传递参数
- 在 Linux 命令行脚本中执行 sudo 等命令时自动输入密码(使用expect)
- 分发系统介绍、expect脚本远程登录、expect脚本远程执行命令、expect脚本传递参数
- 分发系统介绍 expect脚本远程登录 expect脚本远程执行命令 expect脚本传递参数
- 分发系统介绍、expect脚本远程登录、expect脚本远程执行命令、expect脚本传递参数
- Expect循环登录多台服务器执行命令的脚本
- 在linux下如何通过expect正确执行自动切换登录,并且执行命令和脚本
- 使用expect工具ssh登录远程服务器并执行命令操作
- 分发系统介绍expect脚本远程登录expect脚本远程执行命令 expect脚本传递参数
- 分发系统介绍,expect脚本远程登录,远程执行命令,传递参数
- 使用expect和ssh远程执行命令的脚本
- 分发系统介绍,expect脚本远程登录,expect脚本远程执行命令,expect脚本传递参数
- 【shell编程】分发系统介绍、expect脚本远程登录、expect脚本远程执行命令和expect脚本传递参数
- 十七周三次课 2018.02.27分发系统介绍、expect脚本远程登录、expect脚本远程执行命令、expect脚本传递参数
- 使用ctr+c无法终止一个bash脚本,此脚本在循环执行一个需要运行一定时间的命令
- 在linux shell脚本中root切换到普通用户执行脚本或命令的方法
- expect脚本同步文件、指定host和要同步的文件、构建文件分发系统、批量远程执行命令
- linux shell脚本登录远程执行命令,交互通过脚本
- expect实现自动scp和ssh登录后执行命令,并向bash提供返回值
- expect脚本自动化执行线上服务器命令