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.1
Committed: Mon Nov 19 21:42:11 2001 UTC (22 years, 11 months ago) by tdb
Content type: text/plain
Branch: MAIN
Log Message:
Initial set of i-scream ihost plugins. These are derived completely from
statgrab, and offer no new features over it. They do, however, allow for
parts of this code to be replaced in other languages if required.
Only a few minor changes were made, mainly for efficiency, commenting, and
some changes of chop to chomp :)

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     # $Author: tdb1 $
6     # $Id: statgrab.pl,v 1.46 2001/11/14 15:18:25 tdb1 Exp $
7     #
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     # Have to hope this will work really.
19     my($ostype) = `uname -s`; chomp($ostype);
20    
21     # Decide which paths we should use.
22     my($unamebin);
23     if ($ostype eq "SunOS" || $ostype eq "FreeBSD") {
24     # covers: Solaris 7/8
25     # covers: FreeBSD 4.X
26     $unamebin = "/usr/bin/uname";
27     }
28     elsif ($ostype eq "Linux") {
29     # covers: Debian r2.2
30     $unamebin = "/bin/uname";
31     }
32     else {
33     print "i-scream_osver.pl Error: Unable to identify system type - \"$ostype\".\n";
34     print "\"uname -s\" does not report one of the following known types;\n";
35     print " SunOS, Linux, FreeBSD\n";
36     exit(1);
37     }
38    
39     # Run the following components: -
40     &print_ident();
41     &include_osver();
42    
43     # End the program normally.
44     exit(0);
45    
46    
47    
48    
49     # prints out an identifier for this version of the script
50     # this could be used in checks further downstream
51     sub print_ident() {
52     print 'packet.plugins.ident.i-scream_osver i-scream_osver.pl $Revision: 1.46 $';
53     print "\n";
54     }
55    
56     # sub to print pairs of data, separated by a single space character.
57     # If the second argument is undefined, then the pair is still printed,
58     # however, the value shall be displayed as the the 'default' value
59     # if the passed value was undefined.
60     sub print_pair($$$) {
61     my($default, $name, $value) = @_;
62    
63     if (!defined $value) {
64     $value = $default;
65     }
66    
67     # Remove the trailing linefeed if we've not already done so.
68     chomp($value);
69    
70     # print the pair of data with a space inbetween.
71     print "$name $value\n";
72     }
73    
74     # sub to get details of the machine's operating system.
75     sub include_osver() {
76    
77     # Find out details about the operating system
78     # If these values remain undefined, then the print_pair
79     # function shall show the value to be the string "unknown".
80     my($os_name) = `$unamebin -s`;
81     my($os_release) = `$unamebin -r`;
82     my($os_platform) = `$unamebin -m`;
83     my($os_sysname) = `$unamebin -n`;
84     my($os_version) = `$unamebin -v`;
85    
86     &print_pair("unknown", "packet.os.name", $os_name);
87     &print_pair("unknown", "packet.os.release", $os_release);
88     &print_pair("unknown", "packet.os.platform", $os_platform);
89     &print_pair("unknown", "packet.os.sysname", $os_sysname);
90     &print_pair("unknown", "packet.os.version", $os_version);
91    
92     }