2012年4月25日星期三

expect自动执行对话切换到root用户

1.ubuntu上安装expect:
sudo apt-get install expect
2.查看expect安装成功没
dpkg -s expect
状态:
Status: install ok installed

3.查看expect安装到哪个目录

whereis expect
结果:
expect: /usr/bin/expect /usr/bin/X11/expect /usr/share/man/man1/expect.1.gz



4.实现自动切换到root用户的功能
$ vi su_root.exp 
输入如下片段
#!/usr/bin/expect
spawn su - root
expect {
 "密码:" { send "your password\r"; exp_continue }
}
interact


没有评论:

发表评论