ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/ihost-perl/plugins/perl/i-scream_users.pl
Revision: 1.3
Committed: Sat May 18 18:15:57 2002 UTC (22 years, 5 months ago) by tdb
Content type: text/plain
Branch: MAIN
Changes since 1.2: +20 -1 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

# User Rev Content
1 tdb 1.1 #!/usr/bin/perl -w
2    
3 tdb 1.3 #
4     # i-scream central monitoring system
5     # Copyright (C) 2000-2002 i-scream
6     #
7     # This program is free software; you can redistribute it and/or
8     # modify it under the terms of the GNU General Public License
9     # as published by the Free Software Foundation; either version 2
10     # of the License, or (at your option) any later version.
11     #
12     # This program is distributed in the hope that it will be useful,
13     # but WITHOUT ANY WARRANTY; without even the implied warranty of
14     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     # GNU General Public License for more details.
16     #
17     # You should have received a copy of the GNU General Public License
18     # along with this program; if not, write to the Free Software
19     # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20     #
21    
22 tdb 1.1 #-----------------------------------------------------------------
23     # i-scream host plugin - user information collection
24 tdb 1.2 # $Author: tdb $
25 tdb 1.3 # $Id: i-scream_users.pl,v 1.2 2001/12/18 04:07:17 tdb Exp $
26 tdb 1.1 #
27     # A short perl script to parse the output of the users command.
28     #-----------------------------------------------------------------
29    
30    
31     $| = 1;
32    
33    
34     # You'd be silly not to use this ;)
35     use strict;
36    
37 tdb 1.2 # Get the OS type from the args, or try towork it out
38     my($ostype) = $ARGV[0];
39     $ostype = `uname -s` if not defined $ostype;
40     chomp($ostype);
41 tdb 1.1
42     # Decide which paths we should use.
43     my($usersbin);
44     if ($ostype eq "SunOS") {
45     # covers: Solaris 7/8
46     $usersbin = "/usr/ucb/users";
47     }
48     elsif ($ostype eq "Linux" || $ostype eq "FreeBSD") {
49     # covers: Debian r2.2
50     # covers: FreeBSD 4.X
51     $usersbin = "/usr/bin/users";
52     }
53     else {
54     print "i-scream_users.pl Error: Unable to identify system type - \"$ostype\".\n";
55     print "\"uname -s\" does not report one of the following known types;\n";
56     print " SunOS, Linux, FreeBSD\n";
57     exit(1);
58     }
59    
60     # Run the following components: -
61     &include_users();
62    
63     # End the program normally.
64     exit(0);
65    
66    
67    
68    
69     # sub to print pairs of data, separated by a single space character.
70     # If the second argument is undefined, then the pair is still printed,
71     # however, the value shall be displayed as the the 'default' value
72     # if the passed value was undefined.
73     sub print_pair($$$) {
74     my($default, $name, $value) = @_;
75    
76     if (!defined $value) {
77     $value = $default;
78     }
79    
80     # Remove the trailing linefeed if we've not already done so.
81     chomp($value);
82    
83     # print the pair of data with a space inbetween.
84     print "$name $value\n";
85     }
86    
87    
88     # sub to find out the list of all usernames logged
89     # in to the machine and how many there are.
90     sub include_users() {
91    
92     # Find out all users on this machine.
93     my($users) = `$usersbin`;
94     $users = "\n" unless defined $users;
95     chomp $users;
96     my($users_count) = 0;
97     $users_count++ while $users =~ /\w+/g;
98     my($users_list) = $users." ";
99    
100     &print_pair(0, "packet.users.count", $users_count);
101     &print_pair("unknown", "packet.users.list", $users_list);
102     }