Expect script to give multiple inputs

Sukumar R

I want to ssh to list of servers and set a unique value on the each server using expect script.

Example: I've 10 servers. server1 to 10 I've asset tag of the server assettag1 to 10. I want to ssh to each server and update the asset tag value on each server.

Thanks, Sukumar

Pitou

Here is a script that may help you. As you can see the values are passed as arguments to myscript.sh where the expect code is located.

#!/bin/bash
adresses=("192.168.1.1" "192.168.1.2" "192.168.1.3" "192.168.1.4" "192.168.1.5" "192.168.1.6" "192.168.1.7")
hostnames=("ap02" "ap03" "ap04" "ap05" "ap06" "ap07" "ap08")

### Main ###
for cpt in {0..6}
do
        ./myscript.sh ${adresses[${cpt}]} ${hostnames[${cpt}]}
        cpt=$(( $cpt +1 ))
done

Here is how I use the arguments in myscript.sh

#!/usr/bin/expect
set ipaddr [lindex $argv 0];
set hostname [lindex $argv 1];
...

Where $argv 0 is the first argument and $argv 1 the second

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related