Operating System - HP-UX
1834269 Members
91546 Online
110066 Solutions
New Discussion

Interactively answering a question

 
Donald C Nelson
Frequent Advisor

Interactively answering a question

How do I answer the below question interactively in a script from a piped file.

Please mount tape and press Return to continue ...
10 REPLIES 10
Mel Burslan
Honored Contributor

Re: Interactively answering a question


I am not sure if I understood your question correctly but if you are asking how to generate the effect of hitting a return by input pipes, here it is in two different ways:

1.
create a file with a single carriage return character in it (vi myfile, then hit return all by itself and save it)

you can cat this file and pipe it to your script and when the question is asked, it will read the return character from the input pipe


2.
in the script, where it will give you this prompt, you can echo "^M" character to the command (vi the script and create the ^M character by hitting ctrl-V then ctrl-M)

________________________________
UNIX because I majored in cryptology...
Kofi ARTHIABAH
Honored Contributor

Re: Interactively answering a question

You might want to consider crafting something with expect

http://hpux.cs.utah.edu/hppd/hpux/Tcl/expect-5.43/

out of curiousity why would you want to do that?

Good luck.
nothing wrong with me that a few lines of code cannot fix!
Steve Lewis
Honored Contributor

Re: Interactively answering a question

$INFORMIXDIR/bin/ontape -s -L 0 <
EOF

- the blank line between the ontape and the EOF is where it answers your question.

If the backup goes over to a second tape you will have a problem with this solution.

Donald C Nelson
Frequent Advisor

Re: Interactively answering a question

Kofi and Steve, you all hit the nail on the head. I am doing this because of Informix v5 running on hp-ux 10.20. The DBA's for this system is gone and I have to write a script file to archive the logs to disk instead of tape. I have been trying expect for a week but I am a newbie at it and I can't get the sends and expects down. So, I though that I would just try and write a script to take care of this
Sandman!
Honored Contributor

Re: Interactively answering a question

See script attached...
Donald C Nelson
Frequent Advisor

Re: Interactively answering a question

Sandman, thanks for the input and trying to fix my script but it just hangs on "su - informix" and it goes no further.
Sandman!
Honored Contributor

Re: Interactively answering a question

Donald,

Could you post your script.

thx
Donald C Nelson
Frequent Advisor

Re: Interactively answering a question

Sandman, here it is. I'm running expect on the same server as informix so I don't have to spawn anything that is why it is remmed out.
Sandman!
Honored Contributor

Re: Interactively answering a question

Donald,

If you're running Informix locally then you need "spawn" not "send". Replace...

# send -- "su - informix\r"

...with

# spawn su - informix

cheers!
Sandman!
Honored Contributor

Re: Interactively answering a question

Donald...see script attached.

enjoy!