LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 09-05-2013, 08:46 AM   #1
Black187
LQ Newbie
 
Registered: Nov 2005
Posts: 26

Rep: Reputation: 0
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...
 
Old 09-05-2013, 08:58 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,051

Rep: Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852
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.
 
Old 09-05-2013, 11:12 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Try this page for openssl examples http://www.madboa.com/geek/openssl/#cs-smtp
 
1 members found this post helpful.
Old 09-06-2013, 10:05 PM   #4
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (Chicago area)
Distribution: Red Hat (8.0, RHEL5,6), CentOS, SuSE (10.x, 11.x, 12.2, 13.2), Solaris (8-10), Tru64, MacOS, Raspian
Posts: 1,113

Rep: Reputation: 65
Quote:
Originally Posted by schneidz View Post
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.)
 
Old 09-08-2013, 09:45 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
Quote:
Originally Posted by rnturn View Post
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.
 
Old 09-08-2013, 10:19 AM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,051

Rep: Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852
^ 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.
 
Old 09-08-2013, 12:45 PM   #7
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (Chicago area)
Distribution: Red Hat (8.0, RHEL5,6), CentOS, SuSE (10.x, 11.x, 12.2, 13.2), Solaris (8-10), Tru64, MacOS, Raspian
Posts: 1,113

Rep: Reputation: 65
Quote:
Originally Posted by jpollard View Post
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.)
 
Old 09-08-2013, 01:09 PM   #8
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (Chicago area)
Distribution: Red Hat (8.0, RHEL5,6), CentOS, SuSE (10.x, 11.x, 12.2, 13.2), Solaris (8-10), Tru64, MacOS, Raspian
Posts: 1,113

Rep: Reputation: 65
Quote:
Originally Posted by schneidz View Post
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.
 
Old 09-08-2013, 04:25 PM   #9
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
Quote:
Originally Posted by rnturn View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Push output string from script directly into bash / readline command input buffer GreyBeard Linux - Software 3 02-21-2012 12:26 AM
Help on my Linux Homework ! bash shell script / input-output data etc Bebelindo Programming 2 03-03-2009 01:51 PM
Pass output of one command as input to another on bash linuxlover.chaitanya Linux - Newbie 3 01-08-2009 02:46 AM
input into bash script(reading path) dalicros Linux - General 3 05-30-2007 07:54 PM


All times are GMT -5. The time now is 10:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration