Solved

KornShell script to respond to a prompt

Posted on 2001-07-16
9
403 Views
Last Modified: 2013-12-26
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
Comment
Question by:waipahu
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 3

Expert Comment

by:interiot
ID: 6288138
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6290371
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
 

Author Comment

by:waipahu
ID: 6290964
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 3

Accepted Solution

by:
interiot earned 50 total points
ID: 6291023
#! /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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6291119
beside the expect solution, which pgp version are you using
0
 
LVL 8

Expert Comment

by:mnashadka
ID: 6291707
Did you try to use a here document?

pgp -whatever<<EOF
Y
EOF
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6293080
> Did you try to use a here document?

won't work for obvious (security) reason, see my 1'st comment
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6294441
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
 

Author Comment

by:waipahu
ID: 6296550
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

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question