Passing password to the program(application) through shell scripting
am 16.11.2007 11:58:27 von shashianeja
I am writing a shell script to test my application. My application is
based on command line interface. There is a command "cmvclog -in
family". After that my application prompts me for password. I want to
automate that my password should get automatically entered by my
script
Please note that prompt for password is displayed by application
Script
export CMVC_PW_AUTH_TYPE=PW
cmvclog -in man5d7 -family man5d7 -verbose
read $PASSWORD
On running the script my application asks me for password as shown
below. What could be the possible way to enter the password tthrough
shell script instead of reading it through keyboard.
(340) ./Mikely
Enter the cmvc password for login man5d7 on family
man5d7@man5d7@50006:
Re: Passing password to the program(application) through shellscripting
am 16.11.2007 14:56:51 von Icarus Sparry
On Fri, 16 Nov 2007 02:58:27 -0800, shashianeja wrote:
> I am writing a shell script to test my application. My application is
> based on command line interface. There is a command "cmvclog -in
> family". After that my application prompts me for password. I want to
> automate that my password should get automatically entered by my script
>
> Please note that prompt for password is displayed by application
>
>
> Script
> export CMVC_PW_AUTH_TYPE=PW
> cmvclog -in man5d7 -family man5d7 -verbose read $PASSWORD
>
> On running the script my application asks me for password as shown
> below. What could be the possible way to enter the password tthrough
> shell script instead of reading it through keyboard.
>
>
> (340) ./Mikely
> Enter the cmvc password for login man5d7 on family man5d7@man5d7@50006:
The standard answer to this is to use "expect". Something like
#!/usr/bin/expect
spawn cmvclog -in man5d7 -family man5d7 -verbose
expect {Enter the cmvc password*:}
send secretpassword\r
interact
my be enough to handle your problem. There are other solutions which
don't involve expect. How applicable they are depends on how exactly
cmvclog is getting the password. Many programs use routines that read
from /dev/tty, rather than stdin. "expect" handles that case nicely. You
can however have a script that telnets to the local machine, and sends
text "blindly" with suitible sleeps.
If cmvclog just reads from stdin, you may get away with
{
sleep 2
echo secretpassword
sleep 1
cat
} | cmvclog -in .....