user3164140
user3164140

Reputation: 651

How to pass Username and password to an application using shell script?

I want to make script to login into application, its flow is like

  1. Go to perticular directory,(My script=> cd /ld62_prod)
  2. Give one command which will launch application(My script=> drv)
  3. Application will launch and cursor will be pointing where i need to give username.
  4. After giving username it will display next page prompting for password(now cursor is here).

Now my problem is I am able to reach till application launching, but not able to provide Username and password through script.

My sample script is

cd cd /ld62_prod
drv
112233 #username
112233 #password

What I am doing wrong.

Upvotes: 1

Views: 25032

Answers (2)

Sujith PS
Sujith PS

Reputation: 4864

Without Security :

You can use this :

 echo "User name: $0"
 echo "Password: $1"

And you can use the particular values using $0 and $1 .

Refer Shell script for more details .

With Security :

read -s -p "Password: " password

Under Linux (and cygwin) this form works in bash and sh. It may not be standard Unix sh, though.

For more info and options, in bash, type "help read".

$ help read
read: read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
Read a line from the standard input and split it into fields.
  ...
  -p prompt output the string PROMPT without a trailing newline before
            attempting to read
  ...
  -s                do not echo input coming from a terminal

Upvotes: 1

jweyrich
jweyrich

Reputation: 32240

You could use expect, which is a standard tool that can communicate with interactive programs/scripts like yours. Its man page says:

Expect is a program that "talks" to other interactive programs according to a script. Following the script, Expect knows what can be expected from a program and what the correct response should be. An interpreted language provides branching and high-level control structures to direct the dialogue. In addition, the user can take control and interact directly when desired, afterward returning control to the script.

Upvotes: 0

Related Questions