Ahmed Moustafa <[EMAIL PROTECTED]> wrote:

[ That address is bouncing, by the way. ]

> How can I switch user "su" in perl?

It's much easier to do that before running the script.  :-)

  $ su -c ./script.pl

And then once you're root, you can change the real and effective
user ids with the magic $< and $> variables.

>From inside a non-privileged Perl script, the only thing you can
do is re-exec the script via su/sudo and punch in the password.

  #!/usr/bin/perl -l

  exec "sudo", "/usr/bin/perl", $0, @ARGV if $<;

  print " uid: ", getpwuid $<;
  print "euid: ", getpwuid $>;

If you need to run disconnected from the terminal, you should
just put the script in the correct user's crontab.

But you could also use Expect.pm to automate password entry,
or configure sudo not to ask for the password.

-- 
Steve

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to