1

There is a script that requires me to enter the password before it continues:

bash-3.2$ ./script.sh <parameter_list>
Enter the password for the Database: 
..
..

I am interested in capturing the standard output of the script into a log file, while securely passing the password to the script.

I tried to pass the password into standard input as follows:

bash-3.2$ echo "<password>" > /secure/path/password.txt
bash-3.2$ ./script.sh <parameter_list> < /secure/path/password.txt

But this doesn't seem to work. If it did, I could simply use tee to redirect the output to a log file.

3

I think you want expect. This tool can interactively work with commands that need user input. Of course the major pitfall being that you have to know what to expect.

Example (borrowed from http://www.thegeekstuff.com/2010/10/expect-examples/)

#!/usr/bin/expect

set timeout 20

spawn "./hello.pl"

expect "hello"
send "no match : <$expect_out(buffer)> \n"
send "match :  <$expect_out(0,string)>\n"

interact
1

What about

echo "password" | ./script.sh parameter_list ... > output.file

If that doesn' work, then answer this question: what mechanism does the script use to get the password from the user. If it's something like an ssh password, sending it via stdin won't work.

  • Thanks Glenn. It didn't work.. I connect to the Solaris box over SSH and then enter the password manually after running the script. So I guess there is no workaround in this case.. – Kent Pawar Jul 1 '13 at 14:58
  • The best way is to use ssh keys, then you don't need to manually enter the password – glenn jackman Jul 1 '13 at 15:09
  • I think this is a bit different, as after I connect to the box over SSH (PuTTY), I then manually enter the DB password after running the script. I think my solution lies in a Solaris equivalent of Ubuntu's ttysnoop command. – Kent Pawar Jul 1 '13 at 15:32
  • Maybe you want expect: programmatically enter the ssh password then switch to interactive mode to let you enter the db password. – glenn jackman Jul 2 '13 at 1:17
0

If this is your own script, may be you can send the interactive output to stderr.

  • Thanks. Unfortunately its not.. Its a script provided as part of the Oracle EPM installation. – Kent Pawar Jul 1 '13 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.