I have an expect script that will SSH into a list of routers.
The expect script works on a list of routers in a file and is called from a bash script with xargs.
Bash : script get-rtr.sh
#!/bin/bash/usr/bin/xargs -P 10 -L 1 -r ./get-rtr-expect.sh < ./router_list
The expect script will SSH into 10 routers at a time, until it completes the list.
Expect : script get-rtr-expect.sh
#!/usr/bin/expect -fset IPaddress [lindex $argv 0]log into routers and get configs etc
I want to pass 2 more arguments (the same 2 for every router) to the expect script from the bash script, so that ultimately the expect script takes 3 args, and it will look like this:
#!/usr/bin/expect -fset IPaddress [lindex $argv 0]set foo [lindex $argv 1]set bar [lindex $argv 2]log into routers and get configs etc
How can I pass those 2 extra args to each instance of the expect script?
thanks
UPDATE.
I came up with a really ugly way to do it:
Add to the bash script get-rtr.sh:
> router_list_templist=`cat router_list`for i in `echo $list`doecho $i $foo $bar >> router_list_tempdone/usr/bin/xargs -P 10 -L 1 -r ./get-rtr-expect.sh < ./router_list_temp> router_list_temp
I am looping thru the router list, and writing to a new file with the args added. Then feed the new list to the expect script, each line of the line is arg0 arg1 and arg 2.Then wipe it clean at the end.
I don't like this at all. I don't want to create a temp file, but it seems to be working.
All better ideas are welcome.If router_list_temp could be an array of routers with 2 args, rather than a file, that would be better .... it would all live in RAM.
but I don't know how to create and array or pass it to an expect script.