如何向expect脚本里面传递参数
比如下面脚本用来做ssh无密码登陆,自动输入确认yes和密码信息,用户名,密码,hostname通过参数来传递
ssh.exp
#!/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]
相关推荐
linuxwcj 2020-10-21
bluecarrot 2020-08-19
luvzhan 2020-07-28
pimshell 2020-06-27
wiseMale 2020-06-01
SciRui 2020-05-06
BingGoGo技术 2020-03-03
gcong 2020-03-01
linuxhh 2020-02-15
86427019 2020-01-20
tvk 2020-01-09
quzhongwei 2020-01-06
风吹草动 2019-12-09
dmbjzhh 2019-11-08
onetozero 2019-11-08
supetan 2016-05-23
rickenwang 2019-11-03
beiya 2011-07-25