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_osver.pl
Revision: 1.2
Committed: Tue Dec 18 04:07:17 2001 UTC (22 years, 10 months ago) by tdb
Content type: text/plain
Branch: MAIN
Changes since 1.1: +6 -12 lines
Log Message:
Solaris process accounting made me notice the number of times `uname` was
being called. It was way over the top, especially as it's unlikely to
change during an invocation of ihost :) Before it was run by each plugin
every time they were run - in total 50 times a minute :/ Now, it's run once
by ihost at startup, and that's it. The value read at startup is passed as
a command line argument to each plugin. The plugins can fallback on working
out the ostype using `uname` if they don't get given one on the command
line.

File Contents

# User Rev Content
1 tdb 1.1 #!/usr/bin/perl -w
2    
3     #-----------------------------------------------------------------
4     # i-scream host plugin - os details and version
5 tdb 1.2 # $Author: tdb $
6     # $Id: i-scream_osver.pl,v 1.1 2001/11/19 21:42:11 tdb Exp $
7 tdb 1.1 #
8     # A short perl script to grab the os version etc
9     #-----------------------------------------------------------------
10    
11    
12     $| = 1;
13    
14    
15     # You'd be silly not to use this ;)
16     use strict;
17    
18 tdb 1.2 # Get the OS type from the args, or try towork it out
19     my($ostype) = $ARGV[0];
20     $ostype = `uname -s` if not defined $ostype;
21     chomp($ostype);
22 tdb 1.1
23     # Decide which paths we should use.
24     my($unamebin);
25     if ($ostype eq "SunOS" || $ostype eq "FreeBSD") {
26     # covers: Solaris 7/8
27     # covers: FreeBSD 4.X
28     $unamebin = "/usr/bin/uname";
29     }
30     elsif ($ostype eq "Linux") {
31     # covers: Debian r2.2
32     $unamebin = "/bin/uname";
33     }
34     else {
35     print "i-scream_osver.pl Error: Unable to identify system type - \"$ostype\".\n";
36     print "\"uname -s\" does not report one of the following known types;\n";
37     print " SunOS, Linux, FreeBSD\n";
38     exit(1);
39     }
40    
41     # Run the following components: -
42     &include_osver();
43    
44     # End the program normally.
45     exit(0);
46    
47    
48    
49    
50     # sub to print pairs of data, separated by a single space character.
51     # If the second argument is undefined, then the pair is still printed,
52     # however, the value shall be displayed as the the 'default' value
53     # if the passed value was undefined.
54     sub print_pair($$$) {
55     my($default, $name, $value) = @_;
56    
57     if (!defined $value) {
58     $value = $default;
59     }
60    
61     # Remove the trailing linefeed if we've not already done so.
62     chomp($value);
63    
64     # print the pair of data with a space inbetween.
65     print "$name $value\n";
66     }
67    
68     # sub to get details of the machine's operating system.
69     sub include_osver() {
70    
71     # Find out details about the operating system
72     # If these values remain undefined, then the print_pair
73     # function shall show the value to be the string "unknown".
74     my($os_name) = `$unamebin -s`;
75     my($os_release) = `$unamebin -r`;
76     my($os_platform) = `$unamebin -m`;
77     my($os_sysname) = `$unamebin -n`;
78     my($os_version) = `$unamebin -v`;
79    
80     &print_pair("unknown", "packet.os.name", $os_name);
81     &print_pair("unknown", "packet.os.release", $os_release);
82     &print_pair("unknown", "packet.os.platform", $os_platform);
83     &print_pair("unknown", "packet.os.sysname", $os_sysname);
84     &print_pair("unknown", "packet.os.version", $os_version);
85    
86     }