问题描述
我有一个脚本( dobrt ),该脚本在执行时会要求输入密码.我该如何编写一个执行 dobrt 并自动提供密码要求.
I have a script(dobrt) which upon executing asks for a password.How can i write a script which executes dobrt and automatically supplies the password it asks for.
当我执行./dobrt -p file.txt
时,系统要求输入密码.我希望密码由脚本自动发送.这是输出
when i execute ./dobrt -p file.txt
, the system asks for a password. I want the password to be sent in automatically by the script. Here is the output
$ ./dobrt -p file.txt
Found 194 tests to execute
------------ 2010 February 11 11:27:33 ------------
Password: ***************
我尝试为此使用shell和expecxt脚本.这就是我所做的.
I tried using shell and expecxt scripts for this. here is what i did.
我有2个脚本.我从第一个脚本(run_dobrt.sh)调用第二个脚本(run_dobrt.exp).
I have 2 scripts. I call the second script(run_dobrt.exp) from the first one(run_dobrt.sh).
脚本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`
脚本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
现在,当我运行run_dobrt.sh时,出现以下错误 run_dobrt.sh [20]:产生:未找到如何摆脱这个错误并完成这项任务?请帮忙.
Now when i run run_dobrt.sh i get the following errorrun_dobrt.sh[20]: spawn: not foundHow to get rid of this error and get this task done? Please help.
推荐答案
我看到两个问题:
- 在shell脚本的最后一行中,删除命令周围的反引号``它们将导致Expect脚本的输出作为Shell命令执行.
-
在Expect脚本中,更改
- In the last line of your shell script, remove the back-quotes `` around the command,they will cause the output of the expect script to be executed as a shell command.
In the expect script, change
设置密码[lindex $ argv 3];
set PASSWORD [lindex $argv 3];
到
set PASSWORD [lindex $argv 2];
您正在跳过一个论点.
这篇关于当界面要求时,如何使用Shell脚本提供密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!