On Wed, May 30, 2001 at 03:57:44PM -0700, Peter Lemus wrote:
> Hi guys, I keep getting errors on the followin script.
> I need the script to logout all users other then root
> or ipl.
> 
>      1  #!/usr/bin/perl

As mentioned by John Joseph Trammell:
          #!/usr/bin/perl -w
          use strict

>      2  #
>      3  #Purpose: To logout users off the system during after hours.
>      4  #
>      5  open(STDERR,">/tmp/userlog.log") || die $!;
>      6  select (STDERR);
>      7  open(USERS, "/tmp/usersin") || die "can't open the USERS file: $!\n";

Good error checking, though that first die message could use some
elaboration.  E.g. die("Unable to open \"/tmp/userlog.log\": \l$!.\n");


>      8    while (<USERS>) {
>      9          $user=split(//);
>     10           #  chomp $user;
>     11              print "$user\n";
>     12                  # @user="root","ipl";
>     13                    if ($user eq root || $user > eq ipl) {

This should be:
                            if ($user eq 'root' || $user eq 'ipl') {

>     14                   # chomp $user;
>     15                    print "user will NOT be logged out \n";
>     16                    }
>     17                    elseif

And here's the killer:
                            elsif {


>     18  # chomp $user;
>     19  @PIDS=`ps -ef | grep $user | grep -v grep | cut -b 10-14`;
>     20                    while (<@PIDS>){
>     21                            `kill $PIDS`;
>     22                            `kill -9, $PIDS`;
>     23                                 }
>     24   close (USERS);
>     25   close (STDERR);


> root@kerouac/export/shareux 372 >perl -w logout.pl
> "root" may clash with future reserved word at
> logout.pl line 13.
> "ipl" may clash with future reserved word at logout.pl
> line 13.
> "elseif" may clash with future reserved word at
> logout.pl line 17.
> syntax error in file logout.pl at line 19, next token
> "@PIDS"
> syntax error in file logout.pl at line 26, at EOF
> Execution of logout.pl aborted due to compilation
> errors.

Given the above diagnosis of your code, these errors should now make sense.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Reply via email to