Bash script for reading output of linux command and make input
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.
Distribution: openSUSE, Raspbian, Slackware. Older: Coherent, MacOS, Red Hat, Big Iron IXs: AIX, Solaris, Tru64
Posts: 2,321
Rep:
Quote:
Originally Posted by schneidz
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.)
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.
^ 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.
Distribution: openSUSE, Raspbian, Slackware. Older: Coherent, MacOS, Red Hat, Big Iron IXs: AIX, Solaris, Tru64
Posts: 2,321
Rep:
Quote:
Originally Posted by jpollard
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.)
Distribution: openSUSE, Raspbian, Slackware. Older: Coherent, MacOS, Red Hat, Big Iron IXs: AIX, Solaris, Tru64
Posts: 2,321
Rep:
Quote:
Originally Posted by schneidz
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.