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

Hi monks, I have to write a script that run a batch of unix commands. I know I can use the system() call to run the command, but one of the command will prompt me for a password. How do I go about putting a password when this command is executed? I am totally clueless on this. Thanks

Replies are listed 'Best First'.
Re: execute shell command
by borisz (Canon) on Jul 21, 2004 at 22:23 UTC
    Try to use Expect to answer the passwd question.
    Boris
Re: execute shell command
by Fletch (Bishop) on Jul 21, 2004 at 23:55 UTC

    Better than hardcoding a password in the source is to make it so you're not prompted to begin with. If you're trying to run something like ssh or rsh, setup an SSH identity or .rhosts file. If you're trying to run a command as a different user, use sudo and configure it so that the script can be run as the specific target user by the running user without a password.

Re: execute shell command
by greenFox (Vicar) on Jul 22, 2004 at 07:51 UTC

    You haven't really given enough information to say (what command are you running? What authentication is it, system(user)/database/other?) but sudo maybe the answer to your question.

    --
    Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho

      I am trying to automate some maintenace work in the Oracle Calendar. For that particular task, a password is needed. I am trying to figure out a way not to hard code the password, but it doesn't seem to be possible (thought about putting the pwd in a file only readable by crontab, but it can be easily defeated). Any other suggestion?

        I'm not familiar with Oracle Calendar at all, it sounds like the only solution might be to put the password in a file, I have had to do that before for Oracle interfaces. It would be nicer if Oracle allowed the use of keys which at least wouldn't be plain text viewable, you would still be relying on file system (permissions) security though. If a cracker has bypassed file system security you probably have bigger problems...

        --
        Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho