Input in expect script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Input in expect script
# 1  
Old 08-08-2013
Input in expect script

Hi,

i have one problem with this script:

-------------------------------
Code:
cat hostid_gathering

#!/bin/bash

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

echo $LINE
/home/user1/expect_script2
done

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

set HOST [lindex $argv 0]

echo $LINE

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

when i execute:

Code:
./hostid_gathering

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


Last edited by Franklin52; 08-08-2013 at 09:55 AM.. Reason: Please use Code Tags
# 2  
Old 08-08-2013
Hello,

Please change the code as follows and try.

Code:
 
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
# 3  
Old 08-08-2013
Code:
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:
Code:
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
-------------------------------------------
Code:
#!/bin/bash

while read LINE; do

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

-------------------------------------------
cat expect_script2
-------------------------------------------
Code:
#!/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:

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


Last edited by Franklin52; 08-08-2013 at 09:56 AM.. Reason: Please use Code Tags
# 4  
Old 08-08-2013
Please edit post and use Code Tags
# 5  
Old 08-13-2013
it works:
Code:
#!/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}
                  }
}


Last edited by Franklin52; 08-13-2013 at 05:34 AM.. Reason: Please use code tags
# 6  
Old 08-13-2013
Where is your code tags?
# 7  
Old 08-13-2013
Code:
#!/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}
                  }
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Expect script returning string following a found expect.

I'm fairly new to scripting so this might not be possible. I am using Expect with Cisco switches and need to capture the string after finding the expect request. For example, when I issue "show version" on a Nexus switch, I'm looking to capture the current firmware version: #show version ... (0 Replies)
Discussion started by: IBGaryA
0 Replies

2. Programming

Calling another expect script inside an expect script

I have an expect script called remote that I want to call from inside my expect script called sudoers.push, here is the code that is causing me issues: set REMOTE "/root/scripts/remote" ... log_user 1 send_user "Executing remote script as $user...\n" send_user "Command to execute is: $REMOTE... (1 Reply)
Discussion started by: brettski
1 Replies

3. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

4. Shell Programming and Scripting

How to handle scripts that expect an input

Hi I would like to know how to handle my script that expects an input when calling the script and the user doesn't enter anything, I need to re-direct to my helpfile. Bascically here is my script: #!/bin/bash csvdir="/var/local/dsx/csv/general" csvfile="$csvdir/$csvfile"... (3 Replies)
Discussion started by: ladyAnne
3 Replies

5. Shell Programming and Scripting

Expect script without user seeing output or input

I want a shell script to call an expect script but I want the expect script to run in the background so the user is not bothered with what is going on. Is there any way to do this? ---------- Post updated at 08:23 PM ---------- Previous update was at 07:39 PM ---------- got it it was ... (1 Reply)
Discussion started by: los21282
1 Replies

6. Shell Programming and Scripting

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies

7. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies

8. Shell Programming and Scripting

Expect script with file input problems

Hello, I am trying to write an expect script that will ssh into a large number of Cisco routers and add some commands via the cli. The script I wrote works great for one host however I have over 350 routers that this needs to be added to. The problem is I cannot get the script to read the file of... (1 Reply)
Discussion started by: meberline
1 Replies

9. Shell Programming and Scripting

input from a file into an expect script ?

Hi, I have an expect script that logs into a host (via ssh) requests the hostid then exits... I am happy with that. However how can I run the same script in a kind of 'while read line' and enter lots of hosts? My knowledge is still very limited (as you will soon see) so any other ideas would... (2 Replies)
Discussion started by: starsky
2 Replies

10. Shell Programming and Scripting

suppress echo while reading input in expect

Hi all, I tried searching for similar threads. Couldn't get any for Expect scripting. I am trying automate a task which requires login to a machine. The user would be prompted for the password. Now, I want this input to be hidden from being displayed on the screen. Is there... (1 Reply)
Discussion started by: sudhir_onweb
1 Replies
Login or Register to Ask a Question