shell脚本自动化部署-如何向expect脚本里面传递参数

比如下面脚本用来做ssh无密码登陆,自动输入确认yes和密码信息,用户名,密码,hostname通过参数来传递
ssh.exp
Python代码

!/usr/bin/expect*

set timeout 10
set username [lindex argv0]setpassword[lindexargv 1]
set hostname [lindex argv2]spawnsshcopyidi.ssh/idrsa.pubusername@hostnameexpectyes/nosendyes\rexpectpassword:sendpassword\r”

expect eof
执行脚本./ssh.exp root pasword hostname1

expect 接收参数的方式和bash脚本的方式不太一样,bash是通过0...n 这种方式,而expect是通过set <变量名称> [lindex argv<paramindex>],setusername[lindexargv 0]


版权声明:本文为qq_25189001原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。