Input in expect script

Hi,

i have one problem with this script:

-------------------------------

cat hostid_gathering

#!/bin/bash

cat /home/user1/ip_switch | while read LINE; do

echo $LINE
/home/user1/expect_script2
done

------------------------------

cat /home/user1/expect_script2
#!/usr/bin/expect -f

set HOST [lindex $argv 0]

echo $LINE

------------------------------

when i execute:

./hostid_gathering

10.155.249.135
can't read "LINE": no such variable
    while executing
"echo $LINE"
    (file "/home/user1/expect_script2" line 5)

Hello,

Please change the code as follows and try.

 
while read LINE; do

echo $LINE
/home/user1/expect_script2
done < "home/user1/ip_switch"

Make a change for this and let me know if this helps.

Thanks,
R. Singh

10.155.249.135
can't read "LINE": no such variable
    while executing
"set HOST $LINE "
    (file "/home/user1/expect_script2" line 3)

i modified my expect script like that:

cat expect_script2
#!/usr/bin/expect -f

set HOST $LINE
set USER user1
ser PASSWORD Password01

ssh -l $USER $HOST

---------- Post updated at 03:53 AM ---------- Previous update was at 03:44 AM ----------

i have 3 files:

ip_switch (contains only one ip)
hostid_gathering
expect_script2

-------------------------------------------
cat hostid_gathering
-------------------------------------------

#!/bin/bash

while read LINE; do

echo $LINE
/home/user1/expect_script2
done < "/home/user1/ip_switch"

-------------------------------------------
cat expect_script2
-------------------------------------------

#!/usr/bin/expect -f

set HOST $LINE
set USER user1
ser PASSWORD xxxxxxxx

ssh -l $USER $HOST

When i execute ./hostid_gathering this is the output:

10.155.249.135
can't read "LINE": no such variable
    while executing
"set HOST $LINE "
    (file "/home/user1/expect_script2" line 3)

Please edit post and use Code Tags

it works:

#!/usr/bin/expect
set hostlist [open /home/user/ip_switch]
set ipaddrs [read $hostlist]
set user "user"
set pass "xxxxxxx"

foreach line [split $ipaddrs \n] {

        spawn ssh $user@$line 
        expect {
        password: {send "$pass\r"; exp_continue}
                  }
}

Where is your code tags ?

#!/usr/bin/expect
set hostlist [open /home/user/ip_switch]
set ipaddrs [read $hostlist]
set user "user"
set pass "xxxxxxx"

foreach line [split $ipaddrs \n] {

        spawn ssh $user@$line 
        expect {
        password: {send "$pass\r"; exp_continue}
                  }
}