LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-20-2006, 06:18 PM   #1
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Expect scripting


I have an Expect script that I can run, however, I'm having trouble (and I've searched through countless references) figuring out how to read through a file, assign each line to a variable, then "spawn" a command.

Here's the logical notation for it:
Code:
loop while not end of file {
   read from file and assign to variable
   spawn command
}
The file I'm reading from is full of server names, which are one per line:
server.1
server.2
server.3
...

I had written a Perl script to parse through the file then shoot the server name out to the Expect script, but lo and behold, the remote server that contains the access file doesn't have Perl! All I know about it is that it's an ancient HP-UX build, it has Expect libraries, and it's main shell is KornShell.

Before anyone suggests to "translate the Perl script into a KornShell script," I want to leave that to be a worst-case scenario-type deal.
 
Old 09-22-2006, 04:28 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
i would personally take the approach of doing some expect and some ksh. just write a tiny wrapper script in ksh to read the file and run the expect script. never touched ksh myself, bu tin bash you'd say
Code:
for host in $(cat file.txt)
do
  expect script.exp $host
done
and then let expect do the same interactions it always was.
 
Old 09-22-2006, 08:56 AM   #3
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Original Poster
Rep: Reputation: 65
thank you very much, acid.

As for ksh, in some respects it's similar to bash, but in most qualities, it is its own beast - particularily with the parenthesis, different types of evaluations require different parenthesis styles. Ksh does some things more efficiently than bash, but ksh hasn't been "officially" updated since 1988, I believe.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
[Expect scripting] send problem ldp Programming 1 01-24-2005 02:39 PM
expect scripting Deltron3030 Linux - Newbie 2 12-16-2003 01:56 PM
problems with scripting in expect wedgeworth Linux - Software 1 10-07-2003 03:34 PM
expect scripting syntax problems...(catch, echo,....) wedgeworth Linux - Software 2 10-02-2003 09:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration