DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

用expect做自动运行脚本


下面的脚本演示了在Ubuntu上安装expect,写一个切换用户的expect脚本,并运行脚本看到效果的过程。

root@guserver:~# apt-get install expect godu@guserver:~\( cat su.exp #!/usr/bin/expect set timeout 20 set user [lindex $argv 0] set password [lindex $argv 1] spawn su $user expect "Password:" send "\)password\r"; interact godu@guserver:~\( ./su.exp chad mypwd spawn su chad Password: chad@guserver:/home/godu\)

参考:6 Expect Script Examples to Expect the Unexpected (With Hello World)



Published

Feb 1, 2013

Last Updated

Feb 1, 2013

Category

Tech

Tags

  • expect 10
  • linux 158

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor