Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Text from a File into Expect Script 1

Status
Not open for further replies.

RF101

Technical User
May 17, 2006
33
US

I have a file with a list of IPs and a 2nd field: x.x.x.x | 1234

I have an Expect script that requires input:

./runme.exp x.x.x.x 1234

I would like to read the file and use it in the script so I could run the script on multiple servers in a row.

 
Maybe something simple like:

Code:
# for IList in `cat <ip file>.list | awk '{print $1, $2}'`; do  ./runme.exp $IList; done

Where <ip file>.list is your file name with IP and numbers in.

If not then maybe just awk through the <ip file>.list echoing each line through a pipe into the script

Thats assuming your script will work that way most will just test it with:

Code:
echo "123.321.123.10 1234" | ./runme.exp

Good luck
Laurie.
 
This is close.

I need to assign the IP and 1234 to the same string.

./runme.exp IP 1234

Currently it is sending IP and then 1234 in the 2nd loop
 

My List has 2 fields:

IP 4DigitNumber

for IList in `cat <ip file>.list | awk '{print $1, $2}'`;

echo "$IList"; = Only 4DigitNumber without IP

 
Ah OK so that's all you have in the file.list rows of 2 strings ?

lets call that file "file.list" save confusing the brackets ....

So try:

Code:
# for IList in `cat file.list | awk '{print $0}'`; do ./runme.exp $IList; done

Laurie.
 
Thanks for your help. I think you are very close to figuring it out.

Here is what I am getting for output:

file.list:

123.123.123.123 1000
123.123.123.124 1001


# for IList in `cat file.list | awk '{print $0}'`; do
> echo "$IList";
> done
123.123.123.123
1000
123.123.123.124
1001


Here is the output I need:

123.123.123.123 1000
123.123.123.124 1001


Do I need to format my input text file differently?
 
Yes sorry ... thats what I love about this you can always learn something new ;)

This is the way .......

Code:
-bash-3.00$ cat freddie.tat | while read line ; do echo $line; sleep 2; done
10.213.70.1 12345
10.213.70.2 22345
10.213.70.3 32345
10.213.70.4 42345
^C
-bash-3.00$

The for loop splits at string boundaries that why we were getting it across 2 lines ... doh!

So something now like ....

Code:
# cat file.list | while read line ; do  ./runme.exp $line; done

Sorry to mess you around .....

Laurie.
 
Ah may have to wrap $line in " "

Code:
# cat file.list | while read line ; do  ./runme.exp "$line"; done

Time for supper ;)

Laurie
 
You are awesome!

I was just experimenting with a line just like this that I found on another site.

It works!

I also had to make sure my text file used a space delimiter versus a tab.

Thanks for all your help.

 
No probs, BTW: my test file was TAB's so not sure it has to be space as long as its wrapped in double quotes (the $line that is) as without quotes I found that I has similar issues with the line being split on each string .....

My pleasure ... as I say even I learned something tonight.... almost time for bed.

:yawn:

Laurie.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top