?
Solved

KornShell script to respond to a prompt

Posted on 2001-07-16
9
Medium Priority
?
416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
LVL 3

Accepted Solution

by:
interiot earned 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

764 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