首页 > 其他 > 详细

如何向expect脚本里面传递参数

时间:2014-02-25 14:09:51      阅读:298      评论:0      收藏:0      [点我收藏+]
如何向expect脚本里面传递参数
 
比如下面脚本用来做ssh无密码登陆,自动输入确认yes和密码信息,用户名,密码,hostname通过参数来传递
 
ssh.exp
 
Python代码  
#!/usr/bin/expect  
set timeout 10  
set username [lindex $argv 0]  
set password [lindex $argv 1]  
set hostname [lindex $argv 2]  
spawn ssh-copy-id -i .ssh/id_rsa.pub $username@$hostname  
expect "yes/no"  
send "yes\r"  
expect "password:"  
send "$password\r"  
  
expect eof  
 
执行脚本./ssh.exp root pasword hostname1
 
expect接收参数的方式和bash脚本的方式不太一样,bash是通过$0 ... $n 这种方式,而expect是通过set <变量名称> [lindex $argv <param index>],例如set username [lindex $argv 0]

如何向expect脚本里面传递参数

原文:http://www.cnblogs.com/hanframe/p/3564942.html

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