Subversion Repositories sysadmin_scripts

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
148 rodolico 1
#! /usr/bin/env perl
2
 
3
use strict;
4
use warnings;
5
 
6
use File::Slurp; # apt install -y libfile-slurp-perl
7
 
149 rodolico 8
# It is difficult to tell who is on line with a UI based Linux system
9
# as all the cli functions assume the other are logged in via cli.
10
#
11
# This script determines all "real users" (UUID > 1000, but not 'nobody')
12
# and then does a ps aux to see if any of them are online.
13
 
14
 
15
# Copyright 2024 Daily Data, Inc.
16
# 
17
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following 
18
# conditions are met:
19
#
20
#   Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
21
#   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer 
22
#   in the documentation and/or other materials provided with the distribution.
23
#   Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived
24
#   from this software without specific prior written permission.
25
# 
26
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
27
# NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
28
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
 
33
# define the version number
34
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
35
use version;
36
our $VERSION = version->declare("0.0.1");
37
 
148 rodolico 38
my @users;
39
 
40
my @passwords = read_file( '/etc/passwd' );
41
while ( my $line = pop @passwords ) {
42
   next if $line =~ m/^#/;
43
   my @columns = split( ':', $line );
44
   push @users, $columns[0] if $columns[2] >= 1000 && $columns[2] < 65534;
45
}
46
 
47
#print join( "\n", @users );
48
 
49
my $users = join( '\|', @users );
50
print qx/ps aux | cut -d' ' -f1 | sort | uniq | grep '$users'/;
51
 
52
1;
53