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

Fellow MOnks, I Have a interesting question. I Have been working on a logon attempt program with perl. Now the problem, that i am having is an interesting one. The problem that I am having, is that I can't change users through my script. I have tried, suing, the password, and I have tried printing the command. Let's say I did something like.
#!/usr/bin/perl system "su - bob"; print "password";
That wouldn't work, and niether would.
#!/usr/bin/perl system "su - bob"; system "password";
That and I Have one more question, how do I set it up, so that whenever a password is being entered, that it is changed to ****? THanks in advance

20040904 Edit by castaway: Changed title from 'su question'

Replies are listed 'Best First'.
Re: Running as Another User
by Fletch (Bishop) on Sep 03, 2004 at 02:13 UTC

    Aside from the fact that it's a bad idea to hard code passwords in scripts and that system doesn't return until the process it creates has already exited, su reads a password from its tty (if you're not already root). You'd have to use something like Expect to handle this, but a better solution is to get your sysadmin to configure sudo (and install it if needed) to allow you to run the necessary command(s) as the users in question.

Re: Running as Another User
by etcshadow (Priest) on Sep 03, 2004 at 07:09 UTC
    In addition to Expect, there's also IPC::Run, which is good for this sort of thing (co-processes).
    ------------ :Wq Not an editor command: Wq
Re: Running as Another User
by phobia (Sexton) on Sep 03, 2004 at 02:45 UTC
    Thanks, I just looked up expect, I think it is what I am looking for, I didn't know that about the system command. The only reason that I am hardcoding passwords is, is because I have a little project that I want to work with. I am trying to work on something, and when I get everything together and I know everything how I want to know, it I will change it from a hardcode, but it is just faster to hard code passwords in right now, to save time. Thanks.