ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.