Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

KornShell script to respond to a prompt

I am using HP Unix, kornshell.

I am writing a PGP script.
How do code my script to automatically
reply to a prompt that PGP gives:
"Are you sure you want to use this public key (y/N)?"
I want to automatically reply "Y" in my script.
I don't want any human intervention.

HELP

Thanks
0
waipahu
Asked:
waipahu
  • 4
  • 2
  • 2
  • +1
1 Solution
 
interiotCommented:
It depends on the sort of interaction you want.

If the only thing you need to answer is one y/n question, you can just do
     echo "y" | pgp -a -b -c ...

If there are several questions that you want to answer, you can write up a file with y, n, y, etc...  each on a separate line, and do the same sort of thing.
     cat prerecorded_answers | pgp -a -b -c ....

If those don't do what you want, you'll probably want to use Tcl's 'Expect' program.  It'll let you wait for a prompt, then give it an answer, wait for the reply, and answer programmatically based on its reply, etc...  And it lets you see both the question and your automated response, and then it can later give the user control again.
0
 
ahoffmannCommented:
i.g. PGP does not allow to read from STDIN anyhow, just from the tty directly, for obvious reason ;-)
The tty cannot be used by the shell (ksh), as interiot said, Expect may do it.

But even the PGP-developers seemed to need this functionality, sometimes, somehow.
So you may try the hidden option as follows:

    echo Y| pgp +batchmode=1 +NoBatchInvalidKeys=0 <... your opts and args>

This works in PGP 2.x and PGP 5.x, not shure about 6.x

Again, this is a **security hole**, that's why PGP doesn't support it !!
0
 
waipahuAuthor Commented:
None of these worked :(
I didn't try the EXPECT method. I have to check if
we have TCL on our unix system.  If I did use Expect
what would be the code to replay automatically to the
PGP response?

Thanks
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
interiotCommented:
#! /usr/misc/bin/expect -f

spawn pgp -a -b -c ....
expect "Are you sure you want to use this public key (y/N)?"
send "y\r"



I'm not familiar with pgp, but if you then wanted to interact with pgp yourself, you could use an 'interact' command at the end to allow user input.
0
 
ahoffmannCommented:
beside the expect solution, which pgp version are you using
0
 
mnashadkaCommented:
Did you try to use a here document?

pgp -whatever<<EOF
Y
EOF
0
 
ahoffmannCommented:
> Did you try to use a here document?

won't work for obvious (security) reason, see my 1'st comment
0
 
ahoffmannCommented:
is this the same question as
http://www.experts-exchange.com/jsp/qShow.jsp?ta=perl&qid=20152453

Then I'll continue to give comments here not in the perl topic, 'cause it's a PGP problem.

As I've seen you're using PGP 6.5.x which probably does no longer have the NoBatchInvalidKeys option (cannot check this). Pleas try following:
    echo 4| pgp -ke +batchmode=1 userid
    echo y| pgp +batchmode=1 +NoBatchInvalidKeys=0 ...
0
 
waipahuAuthor Commented:
Thank you very much.
My Unix systems guy loaded TCL and Expect on our system
and I generated the script using autoexpect script
provided with the installation. It's pretty cool that
autoexpect script. It's like a macro recorder.

Anyway, thanks for leading me in the right direction!!!

Aloha!
How's the job market on the mainland uSA?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now