satyakm has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I am a beginner in linux, perl & shell scripting. I would like to automate the following scenario on a linux environment: 1. Execute the command line utility 2. Provide the username and password. 3. Echo whether login was successful or failure. Note: I would like to read valid and invalid usernames/passwords from a different file. Thanks in advance Satish

Replies are listed 'Best First'.
Re: Automating command line utility
by moritz (Cardinal) on Oct 03, 2008 at 09:04 UTC
    Most programs that read passwords don't read them from the standard input, but try to read directly from the terminal. If that's the case, you need expect (or something similarly ugly) for that.
      The OP said he was using Linux. In that case, one can simple open /dev/tty and read from it. This reads from the terminal - no expect needed.
        one can simple open /dev/tty and read from it

        I don't think so, opening /dev/tty is useful, for instance, when you want to ask the user for a password and don't want it comming from stdin, but the OP seems to be automating some program that asks for login/passwd probably via its /dev/tty and that's what Expect is for.

        Under the hood, Expect creates a pair of master/slave pseudo ttys (via IO::Pty), forks a new process and sets /dev/tty on the child to be the slave pseudo tty. Then the parent process, through the master pty, can read and write to the child /dev/tty.

        It's not done with reading form /dev/tty, sine satyakm also wants to supply data. And reading from and writing to the same device isn't something that I'd recommend a beginner to do himself, which is why I recommended using something that wraps that process for him/her.
Re: Automating command line utility
by Perlbotics (Archbishop) on Oct 03, 2008 at 10:38 UTC

    Hm..., if I would try to write a naive hacker-tool, I would take a long list of valid and invalid usernames/passwords and try to automate the whole procedure like

    1. executing a command line utility,
    2. provide username/password,
    3. check if the login was successful or failure.

    Maybe you can provide us with some more background information on what you attempt to do and what you have done so far? It is likely that a solution to your problem already exists, but knowing the bigger picture would help to give proper and better advice.
    E.g., what concrete command line utility do you intend to use? Are there special keywords to look after? What to do after successful login? Remote or local application? etc.

    Although I assume your intentions are legitimate, there were less subtle cases where helping would do no good, so please forgive me my initial suspicion - especially since this is your first post.