Expect "interact" fails when called from another script
So, I have an expect script (let's call it expect.exp) that takes 3 arguments. It logs into a remote server, runs a set of commands, then hands control over to the user by the "interact" command. If I call this script from the command line, it works properly.
Now I'd like to apply this script to several servers-- log in, view the automated command output, interact as needed, log out, and get jumped straight to the next server. The reasonable approach, it seems, is to create a file that has the parameters in some nice format, like CSV, then use a wrapper to call the nice, proven expect script... something like:
I would expect this to log on, run the automated commands, hand me control, and wait for me to log off; then, once I've logged off that particular server, it would automatically log me onto the next one, run the automated commands, hand over control... you get the idea... until the list is finished. Instead, it logs on to the first server, runs the commands, apparently logs off, and drops me back to a prompt on the server I'm running this from. Only the first line of inputs is used. Why is that? This seems straightforward enough, but apparently it isn't. I'd like to understand this behavior and see how to fix it.
Last edited by treesloth; 02-11-2010 at 06:00 PM..
I am not sure if you code example was complete. I tried replicating with a simple shell script:
Then did the following:
In this case, it doesn't process the arguments. If I do the following, which matches your example
Then, no matter what I type, I will get 1 2 3 as output. Are you trying to be prompted for your opt1, opt2, opt3 arguments everytime? If so, this isn't the correct way to do it.
I would keep an iterator of the the number of hosts or times you wish to run your script, and move the readline way from the "while" line & change your expect script to prompt for the variables.
Ok, I've reviewed this a little more... when I rewrote my structure as a for loop instead of while, it worked. So, I suspect that the problem is in the while structure rather than the expect/bash interaction. Let me back-burner this and study it a bit more. Thanks for the reply, but it appears I might have given faulty information in my OP.
Hello.
System : opensuse leap 42.3
I have a bash script that build a text file.
I would like the last command doing :
print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt
where :
print_cmd ::= some printing... (1 Reply)
Hi All,
i am trying to ssh to a remote machine and execute certain command to remote machine through script.
i am able to ssh but after its getting hung at the promt and after pressing ctrl +d i am gettin the out put as
expect: spawn id exp5 not open
while executing
"expect "$" {... (3 Replies)
Ladies & Gents,
Can one of you gurus please show me a very simple "expect" script to change the password in Solaris in a script, please? Nothing fancy, no error checking, no nothing. Just to change the password of a new user, it's all.
Many thanks in advance. U guys have honestly earned my... (1 Reply)
Hello everyone,
I am having problems figuring this out.
This script below is supposed to create a list of file names with their "md5sum", in a file "lib-list.txt"
When I run it "sh component-list.sh " I get this:component-list.sh: 4: component-list.sh: function: not found
component-list.sh:... (4 Replies)
Hello All,
I am writing an Expect Script to execute some commands over ssh then exit the script.
The script works just fine if I automate everything and assuming the correct password was entered.
So this Expect Script gets executed from a Bash script... From the Bash script I pass along an... (0 Replies)
Hi,
I was trying to call "script <an ip add>" command from .profile file to log everything whenever anyone logs in to this user. I did the following at the end of .profile. 1) Extracted the IP address who logged in 2) Called script < ip add> . The problem I am facing is all, aliases etc. written... (3 Replies)
Hi,
I issue smbclient on a Linux REd hat server :
smbclient -L ***.16.0.42 -U domaine/Administrator
Password:
Domain= OS= Server=
Domain= OS= Server=
Sharename Type Comment
--------- ---- -------
IPC$ IPC IPC distant
... (0 Replies)
I need to take a string (stringA) check it for spaces and replace any spaces found with an equal (=) sign.
This is not working. There are spaces between each component:
$StringA | tr "" ""
The error returned is:
test: Specify a parameter with this command
Can you help? (3 Replies)
Hi Unix Gurus,
I have written a shell script to unfreeze all frozen media in NetBackup. Here is the script written on HP-UX using ksh:
***********************************************
set -x
cd $HOME
rm -f frozentest
rm -f mediaserver
cd /usr/openv/netbackup/bin/admincmd
pbrun... (2 Replies)