How to use a shell script to provide a password when the interface asks for it

I have a script ( dobrt ) that asks for a password after executing the request. How can I write a script that does dobrt and sends the password automatically.

when I execute ./dobrt -p file.txt , the system asks for a password. I want the password to be sent automatically using a script. Here is the conclusion

 $ ./dobrt -p file.txt Found 194 tests to execute ------------ 2010 February 11 11:27:33 ------------ Password: *************** 

I tried using shell and expecxt scripts for this. here is what i did.

I have 2 scripts. I call the second script (run_dobrt.exp) from the first (run_dobrt.sh).

Script 1: run_dobrt.sh

 #!/bin/ksh TESTCASE_HOME="/home/abhijeet/code/testcases"; TESTCASE_LIST="file.txt"; PASSWORD="*****"; echo "Running Expect Script" `./run_dobrt.exp $TESTCASE_HOME $TESTCASE_LIST $PASSWORD` 

Script 2: run_dobrt.exp

 #!/usr/local/bin/expect -f set TESTCASE_HOME [lindex $argv 0]; set TESTCASE_LIST [lindex $argv 1]; set PASSWORD [lindex $argv 3]; set timeout 200 spawn $TESTCASE_HOME/dobrt -p $TESTCASE_HOME/$TESTCASE_LIST expect "*?assword:*" {send -- "$PASSWORD\r";} expect eof 

Now, when I run run_dobrt.sh, I get the following run_dobrt.sh error [20]: spawn: not found How to get rid of this error and complete this task? Please, help.

+2
shell expect
Feb 11 '10 at 6:16
source share
3 answers

What is dobrt? Is this a homemade program? If so, I think you will have to transcode it to parse the extra argument that the password takes. Then you can pass this passowrd to dobrt the same way you do it, like "-p file.txt" on the command line (via script).

+1
Feb 11 '10 at 7:27
source share

I see two problems:

  • In the last line of the shell script, remove the back quotation marks `` around the command, they will cause the expected script to output as a shell command.
  • Waiting for a script, change

    set PASSWORD [lindex $ argv 3];

to

 set PASSWORD [lindex $argv 2]; 

you will skip the argument.

+1
Feb 12 2018-10-12
source share

If the password is the only dobrt request for input, you can try the following:

Script 1: run_dobrt.sh

 #!/bin/ksh TESTCASE_HOME="/home/abhijeet/code/testcases"; TESTCASE_LIST="file.txt"; PASSWORD="*****"; ./run_dobrt.exp $TESTCASE_HOME $TESTCASE_LIST << EOF $PASSWORD EOF 
0
Feb 11 '10 at 21:52
source share



All Articles