in reply to Can the username be represented differently ?

You may want to look at getpwnam(). Reading the documentation, it appears that if you call it in a scalar context giving it the username, you will get back the UID:

$uid = getpwnam($name);
Then you can replace as desired.

As to using the PID (process ID) or GID (group ID), many systems only carry a PID up to a certain value, such as 65535, then wrap back around, so on a busy system you can wrap within a very short time. As to using the GID, this might point you only as far as a group the user was in, but not necessarily down to the particular user, which would not be as helpful should you be trying to track down one of your users accused of spamming.

Hope that helps.

Replies are listed 'Best First'.
Re^2: Can the username be represented differently ?
by peterr (Scribe) on Jun 28, 2004 at 05:44 UTC
    Hi,

    Thanks for your reply. It's been a few mths since I used Perl, the file is CMOD to 744 like the other perl files, I upload it in ascii, yet keep getting the old "premature end of script headers" msg. Do I need any modules to run this ?

    #!/usr/bin/perl -wT $name = 'myusername'; $uid = getpwnam($name); print "$uid: $uid;


    Peter

      744 translate to "rwxr--r--", but if you are running it as a CGI for testing you probably need it set as 755 ("rwxr-xr-x"). Also, in such a case, you likely want to include $|=1; after the #!/usr/bin/perl -wT line. You may also want to check the webserver error log to see if there is anything else occurring.

      Hope that helps.

        The code now looks like this

        #!/usr/local/bin/perl -wT $|=1; $name = 'myusername'; $uid = getpwnam($name); print "$uid: $uid;


        but I'm still getting the 500 msg in the browser, and the web logs say "Premature end of script headers: /home/myusername/cgi-bin/getvars1.pl

        I think I had better check the forums at the hosts to see if anything has changed since last I used Perl, however I did just run FormMail.pl from the same path, it has a 744 and it worked just fine ??

        Thanks,

        Peter