input from a file into an expect script ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting input from a file into an expect script ?
# 1  
Old 04-16-2008
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 be appreciated.

I am trying to update a server list with hostids for each host. I have never logged onto each host before and thus have not set up ssh_keygens.

I have attempted to run the following, but it does not like the host input...

> cat ./hostid_gathering

#!/bin/bash

cat ./host_list | while read LINE; do

./expect_script
done

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

> cat expect_script

#!/opt/sfw/bin/expect -f

set timeout -1

set USER "me"
set PASSWORD "my_password"
set HOST "$LINE" <------ Input from the while script does not work

spawn ssh -l $USER $HOST
expect "assword:"
send "$PASSWORD\r"

expect "*%"

send "hostid; exit\r"


expect; # waits for eof, so output is flushed?

puts "\n\nexpect script exiting normally\n";

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

> ./hostid_gathering

can't read "LINE": no such variable
while executing
"set HOST "$LINE" "
(file "/expect_script" line 7)
can't read "LINE": no such variable
while executing
"set HOST "$LINE" "
(file "/expect_script" line 7)

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

Any help would be greatly appreciated...

My next worry will be when the ssh asks for a yes or no answer first, before requesting a Password response.
# 2  
Old 04-16-2008
When you do "./expect_script" you can "./expect_script $LINE" and inside the expect script you can do :
set HOST [lindex $argv 0]
# 3  
Old 04-16-2008
MySQL

Thanks sysgate - that worked perfectly. Smilie
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. Shell Programming and Scripting

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... (6 Replies)
Discussion started by: elilmal
6 Replies

3. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 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 script to take input from file, match on it in file 2 and input data

All, I am trying to figure out a script to run in windows that will allow me to match on First column in file1 to 8th Column in File2 then Insert file1 column2 to file2 column4 then create a new file. File1: 12345 Sam 12346 Bob 12347 Bill File2:... (1 Reply)
Discussion started by: darkoth
1 Replies

7. 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

8. 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

9. 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

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