Find the answer to your Linux question:
Results 1 to 5 of 5
How to give inputs to a program through shell script during runtime if the program asks for user input while it is being executing? A program is being invoked by ...
  1. #1
    Just Joined!
    Join Date
    Jan 2008
    Location
    India
    Posts
    4

    Passing values to Program during runtime invoked through shell script

    How to give inputs to a program through shell script during runtime if the program asks for user input while it is being executing?

    A program is being invoked by the help of shell script. This program asks the username and password for authentication process.
    How can I give the same using shell script so that it can be automated one.

    Below is my Shell Script:


    #!/bin/bash
    #
    # Script to Authentiacate a user
    #

    # The program Authenticate takes the IP Address to connect.
    # After successful connection it asks for username and password
    # to authenticate user.

    Authenticate 192.1.2.65

    # How can I pass the same if username is "guest" and
    # password is "guest".

  2. #2
    Just Joined!
    Join Date
    Dec 2007
    Location
    bangalore
    Posts
    38
    from the shell script u can pass command line arguments like u pass from the command prompt
    eg;; in ur script pass it like this
    ./test guest guest
    if u have stored this username and passwd in a variable like user and passwd
    pass to the prgm like this
    ./test $user $passwd
    and in the pgm collect it through argv[] and argc....hope this helps

  3. #3
    Just Joined!
    Join Date
    Jan 2008
    Location
    India
    Posts
    4
    Thanx for your reply.

    Perhaps you have mistaken my prob.
    My problem is to pass values to a program which is already running, which can't be passed as command line arguments.
    I am using the IP address as a command line argument to the program "Authenticate".

    BUt at Runtime it asks the value of a particular field like the username and then the password for the validation.
    How these can be handled in shell script?

    Thanking U in Advance.

  4. #4
    Just Joined!
    Join Date
    Dec 2007
    Location
    bangalore
    Posts
    38

    Smile

    then if thats the case i think u should use environment variables....this can help u at runtime for sure...y not try that........

  5. #5
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    You can try feeding them by redirecting stdin to a file, or directly like this:

    Code:
    $ cat << EOF
    > one
    > two
    > three
    > the next line will exit
    > EOF
    one
    two
    three
    the next line will exit
    $
    You get the idea... You can do the same in a script. The input should be sent to the program until it reaches the EOF mark.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...