Link to home
Start Free TrialLog in
Avatar of waipahu
waipahu

asked on

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
Avatar of interiot
interiot

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.
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 !!
Avatar of waipahu

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of interiot
interiot

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
beside the expect solution, which pgp version are you using
Did you try to use a here document?

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

won't work for obvious (security) reason, see my 1'st comment
is this the same question as
https://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 ...
Avatar of waipahu

ASKER

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?