Expect "interact" fails when called from another script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Expect "interact" fails when called from another script
# 1  
Old 02-11-2010
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:

Code:
while read LINE; do
     (assign each field of the line to a variable; say opt1, opt2, opt3)
     ./expect.exp opt1 opt2 opt3
done

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..
# 2  
Old 02-11-2010
I am not sure if you code example was complete. I tried replicating with a simple shell script:

Code:
#!/bin/bash
echo $1 $2 $3

Then did the following:
Code:
while true; 
   do
      test.sh
   done

In this case, it doesn't process the arguments. If I do the following, which matches your example

Code:
while true; 
   do
      test.sh 1 2 3
   done

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.
# 3  
Old 02-11-2010
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

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)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Expect: spawn id exp5 not open while executing "expect "$" { send "sudo su -\r" }"

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)
Discussion started by: Siddharth shivh
3 Replies

3. Shell Programming and Scripting

Can someone please show me a very simple "expect" script to change password in Solaris please?

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)
Discussion started by: Hiroshi
1 Replies

4. Shell Programming and Scripting

Bash script fails with "function: not found" error

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)
Discussion started by: joemb
4 Replies

5. Shell Programming and Scripting

Expect Scripting - Using the "interact" command?

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)
Discussion started by: mrm5102
0 Replies

6. UNIX for Dummies Questions & Answers

Problems with "exit" called from function in bourne script

Hi everyone. #!/sbin/sh EXITING() { umount /FOLDER rm -Rf /FOLDER echo "EXIT" exit 0 } EXITING echo "OK" (8 Replies)
Discussion started by: vacadepollo
8 Replies

7. UNIX for Advanced & Expert Users

All alias in .profile lost when "script" command is called

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)
Discussion started by: amicon007
3 Replies

8. Windows & DOS: Issues & Discussions

Samba (SMB) client fails: "Called name not present"

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)
Discussion started by: big123456
0 Replies

9. UNIX for Dummies Questions & Answers

#!/bin/sh script fails at StringA | tr "[x]" "[y]"

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)
Discussion started by: by_tg
3 Replies

10. HP-UX

Shell Script fails with "can't connect to client"

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)
Discussion started by: sseenu79
2 Replies
Login or Register to Ask a Question