Added client work scripts
[clearscm.git] / clients / GD / FSMon / fsmon
1 #!/bin/env /usr/local/bin/perl
2 ################################################################################
3 #
4 # File:         fsmon
5 # Revision:     0.1
6 # Description:  Monitor filesystem growth
7 #
8 # Author:       Andrew@ClearSCM.com
9 # Created:      Thu Dec 11 10:39:12 MST 2008
10 # Modified:
11 # Language:     Perl
12 #
13 # (c) Copyright 2008, ClearSCM, Inc., all rights reserved.
14 #
15 #################################################################################
16 use strict;
17 use warnings;
18
19 use FindBin;
20 use Getopt::Long;
21 use Net::Domain qw(hostname);
22
23 use lib ($FindBin::Bin, "/cleartrig/ent/SNSD/muos/ccadm_tools/vobs/ranccadm/scripts/lib");
24
25 use Display;
26 use Rexec;
27 use Filesystem;
28 use FsmonDB;
29
30 # This is a non-standard, but commonly used prompt around here. For
31 # EAST systems they use a terminator of "]$" as in "[p6258c@ceast1
32 # p6258c]$ " however on ranray it's more like "[ranray/home/pwit]
33 # ". So we look for both.
34 use constant PROMPT => qr'(\]\$|\] $)';
35
36 my %_opts;
37
38 sub usage (;$) {
39   my ($msg) = $_;
40
41   my $usage = "ERROR: $msg\n\n" if $msg;
42
43   $usage .= <<END;
44 Usage: $FindBin::Script\t[-us|age] [-v|erbose] [-d|ebug]
45
46   -us|age:           Display usage
47   -ve|rbose:         Turn on verbose mode
48   -d|ebug:           Turn on debug mode
49 END
50
51   my $pager = $ENV{PAGER} ? $ENV{PAGER} : "more";
52
53   system "echo \"$usage\" | $pager";
54
55   exit 1 if $msg;
56 } # usage
57
58 # Main
59
60 GetOptions (
61   \%_opts,
62   verbose       => sub { set_verbose },
63   debug         => sub { set_debug },
64   usage         => sub { usage; exit 0 },
65 );
66
67 # Connect to database
68 my $fsmondb = new FsmonDB ("fsmonadm", "fsmonadm");
69
70 # Take a snapshot of all systems
71 verbose "Taking snapshots...";
72
73 foreach ($fsmondb->getSystem) {
74   verbose "Snapshotting $_";
75
76 #  my ($errno, $errmsg) = $fsmondb->snapshot ($_, PROMPT);
77   my ($errno, $errmsg) = $fsmondb->snapshot ($_);
78
79   warning "Unable to take snapshot of $_\n$errmsg"
80     if $errno != 0;
81 } # foreach
82
83 verbose "Done";