LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash script for reading output of linux command and make input (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-for-reading-output-of-linux-command-and-make-input-4175476027/)

Black187 09-05-2013 07:46 AM

Bash script for reading output of linux command and make input
 
Hello,

How can I make an bash script which makes an "openssl" command, and when the "openssl" command ask's a quiestion, the bash script automaticly make a response.

Example, I run "openssl ..." and it ask for my hostname - how do I automate this response with bash script.

I tried googleing it, but no luck... :(

schneidz 09-05-2013 07:58 AM

this is what expect was created for but i suspect there is a more graceful way of providing openssl the info it needs via commandline arguments.

chrism01 09-05-2013 10:12 PM

Try this page for openssl examples http://www.madboa.com/geek/openssl/#cs-smtp

rnturn 09-06-2013 09:05 PM

Quote:

Originally Posted by schneidz (Post 5022272)
this is what expect was created for but i suspect there is a more graceful way of providing openssl the info it needs via commandline arguments.

I would urge testing commands that pass passwords on the openssl command line beforehand. It might be possible to see the password on the command line using ps, top, htop, etc. I haven't tested it but I'm pretty sure this wouldn't be the case when running openssl inside an Expect script. (Though the Expect script would have to either contain the password -- not good -- or be able to read it from a protected file readable only by the user.)

jpollard 09-08-2013 08:45 AM

Quote:

Originally Posted by rnturn (Post 5023387)
I would urge testing commands that pass passwords on the openssl command line beforehand. It might be possible to see the password on the command line using ps, top, htop, etc. I haven't tested it but I'm pretty sure this wouldn't be the case when running openssl inside an Expect script. (Though the Expect script would have to either contain the password -- not good -- or be able to read it from a protected file readable only by the user.)

Not "might be possible" but "is possible". a simple ps auxff will list all the parameters of a command.

schneidz 09-08-2013 09:19 AM

^ never used openssl but judging by the name it uses some sort of key based authentication. I was merely suggesting to the op that it would probably be more practical to use the built-in parameters of the command rather than kludge something together with expect.

rnturn 09-08-2013 11:45 AM

Quote:

Originally Posted by jpollard (Post 5024068)
Not "might be possible" but "is possible". a simple ps auxff will list all the parameters of a command.

I thought there was a way that an application could prevent the system from seeing all the command line parameters used when it was launched though I would hazard a guess that such capability might be UNIX-flavor/variant dependent. (I seem to recall that Oracle was good about fiddling around with the information one would see with 'ps', 'top', and company.)

rnturn 09-08-2013 12:09 PM

Quote:

Originally Posted by schneidz (Post 5024081)
I was merely suggesting to the op that it would probably be more practical to use the built-in parameters of the command rather than kludge something together with expect.

Kludge? You're not being fair to Expect as a programming language; there's a lot of power in it that goes beyond the simple "how to define new passwords for N users" scripts you see floating about. Granted... much of that power is based on a language (Tcl) that doesn't seem to get used too much nowadays but it's still very useful in the right situations. The OP's case seems to be one of those (IMO). In the past, even though the shebang line says 'expect', I've gotten to the point in some of my more elaborate Expect scripts where I'm not sure if I'm writing an Expect script with Tcl extensions or a Tcl script with Expect extensions. And I use it infrequently enough -- as I expect (no pun intended) is true of most others -- that I sometimes have to sit and stare at a script for a while when I need to make changes until the "Oh yeah..." moment when logic comes back to me. (That is almost certainly an indictment of my commenting -- or lack thereof -- than of the language itself.) So maybe 'kludge' wasn't so far off after all. :D

jpollard 09-08-2013 03:25 PM

Quote:

Originally Posted by rnturn (Post 5024142)
I thought there was a way that an application could prevent the system from seeing all the command line parameters used when it was launched though I would hazard a guess that such capability might be UNIX-flavor/variant dependent. (I seem to recall that Oracle was good about fiddling around with the information one would see with 'ps', 'top', and company.)

You can fiddle around with the utilities... and not show it, but that doesn't block it (/proc/<pid>/cmdline). Now they could even fiddle around with /proc... but it will more likely just screw up the system.

You USED to be able to change pointers in the argv vector and change what was visible... but that no longer works as what the user process gets is a COPY of the parameters, not the original (kernel/user separation). Even when it worked, the parameters were visible for a time.


All times are GMT -5. The time now is 02:44 PM.