1751743 Members
5281 Online
108781 Solutions
New Discussion юеВ

Re: unix script

 
SOLVED
Go to solution
Jade Bulante
Frequent Advisor

unix script

I'm writing a unix script that starts up a program called pgp. When it starts up it asks me a question that I would want to answer "yes" all the time. Can you help me??
10 REPLIES 10
James R. Ferguson
Acclaimed Contributor
Solution

Re: unix script

Hi Jade:

I'm going to assume that the program does a "read" looking for the "yes" response. In that case, put "yes" into a file and redirect that file, like this:

# ./mything < ./myresponse

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: unix script

Hi:

I don't suppose it could be as simple as
echo "yes" | command

If you have more than one line you could build a tempfile
echo "yes" > /tmp/yn
echo "no" >> /tmp/yn
echo "exit" >> /tmp/yn

command < /tmp/yn
rm /tmp/yn

Clay
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: unix script

Hi Jade:

PGP usually allows the '--batch' option which suppresses all interacxtive input. This may fix you.

Clay
If it ain't broke, I can fix that.
Joseph C. Denman
Honored Contributor

Re: unix script

you could try:

/what/ever/dir/pgp << EOF
yes
EOF



...jcd...
If I had only read the instructions first??
Jade Bulante
Frequent Advisor

Re: unix script

I tried the steps you guys gave me but pgp is still waiting for a "yes" response.

I tried all of them.
It's asking "do you want to use this public key?" and I need a "yes" response.




Joseph C. Denman
Honored Contributor

Re: unix script

This is not a gui program is it?

All of these response should have worked.

Exactly how are you starting the program?

...jcd...
If I had only read the instructions first??
Satish Y
Trusted Contributor

Re: unix script

Your script may need multiple responses...

try with:

/dir1/pgp << !
yes
yes
!

you may use multiple "yes", there is no harm...

Cheers...
Satish.
Difference between good and the best is only a little effort
A. Clay Stephenson
Acclaimed Contributor

Re: unix script

Hi Jade:

The fundamental problem is that this input is not coming from stdin but another file descriptor. You could probably use lsof to determine the fdes and then within the shell do an exec 4
But a better way is to use the correct options for pgp. This site contains the documentation you need and in particular how to run pgp in an automated environment:
http://www.gnupg.org
If it ain't broke, I can fix that.
Jade Bulante
Frequent Advisor

Re: unix script

I'm starting the program by calling a script called script:
In that script file is the following

pgp -e filename username

This geberates the question that I have to answer with a "yes".