in reply to simple automated login

In Unix the only way to get root privileges is by executing a setuid root program. You could make your script setuid and use suidperl, or you could run a separate setuid program such as "su".

If your script is setuid, then you don't have to request a root password since you can regain root privileges after dropping them just by re-exec'ing your script. It's generally a good idea to drop root privileges any time you don't need them by $)=$(; $>=$<;.

If you're using "su" you'll need to use Expect or Expect::Simple to feed the password to the "su" command.

Replies are listed 'Best First'.
Re^2: simple automated login
by Fletch (Bishop) on Aug 31, 2004 at 02:39 UTC

    Much better to use sudo with an appropriate sudoers configuration which lets you run the command (or limited set of commands, or a wrapper around that limited set of commands) without having to bother with any passwords.

Re^2: simple automated login
by Anonymous Monk on Sep 01, 2004 at 15:36 UTC
    Your suggestion of sending su to Expect led me to recipe 15.13 of Perl Cookbook, "Controlling Another Program with Expect". It works. Thanks. The problem this solves is that an application program needs to install itself, and needs root priviledges to create the /usr/share and other directories. Hence the need to have code that will log in as root. Thanks again.