The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Expect script with file input problems meberline Shell Programming and Scripting 1 05-29-2008 05:40 PM
File as input for a script innocentspirit Shell Programming and Scripting 5 10-26-2007 01:03 AM
suppress echo while reading input in expect sudhir_onweb Shell Programming and Scripting 1 07-23-2007 10:54 AM
Script for reading an input file gzs553 Shell Programming and Scripting 1 10-17-2006 07:55 AM
file as input for script finster Shell Programming and Scripting 1 11-11-2004 06:27 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-16-2008
starsky starsky is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 7
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 (permalink)  
Old 04-16-2008
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,322
When you do "./expect_script" you can "./expect_script $LINE" and inside the expect script you can do :
set HOST [lindex $argv 0]
  #3 (permalink)  
Old 04-16-2008
starsky starsky is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 7
Thumbs up

Thanks sysgate - that worked perfectly.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0