Tuesday, 12 June 2012

Check_file with date for HP UX

today just able to get the solution for checking file for HP-UX.

Issue: I need to check file certain file everyday using GWOS and nagios as a base.
Becoz the hp-ux used perl scripting, so for me its really challenging.
If using bash scripting its should be no problem.

GWOS server = Redhat 5.6
Target = HP-UX server.
example file : /tmp/test_20120920.csv

create file end with .pl (for plugin)
example : vi check_ftpget.pl

add below details on GWOS server:

## Written 12/5/00 Jeremy Hanmer
# $Id: check_ftpget2.pl,v 2005/02/07 19:33:32 hmann Exp $
use POSIX qw/strftime/;
use strict;
use Net::FTP;
use Getopt::Std;

use vars qw($opt_H $opt_u $opt_p $opt_f $opt_date);

my $date = strftime "%Y%m%d", localtime;

my $host = $opt_H ||
    die "usage: check_ftp.pl -H host [<-u user> <-p pass> <-f file>]\n";

my $username = $opt_u || 'anonymous';
my $pass = $opt_p || "$ENV{'LOGNAME'}\@$ENV{'HOSTNAME'}" ;

my $file ="$opt_f$date.csv";

my $status = 0;
my $problem;
my $output = "ftp ok $file";

my $ftp = Net::FTP->new("$host") ||

$ftp->login("$username", "$pass") ||

$ftp->get($file) ||
    &crit("get") if $file;

sub crit()
    $problem = $_[0];
    $status = 2;
    if ( $problem eq 'connect' ) {
        $output = "can't connect";
    } elsif ( $problem eq 'login' ) {
        $output = "can't log in";
    } elsif ( $problem eq 'get' ) {
        $output = "cant get $file";

print "$output\n";
exit $status;


test the scripting at GWOS server.
check-ftpget3.pl -H XXXXX -u nagios2 -p XXXXXX-f /tmp/test_
ftp ok /tmp/test_20120612.csv

ok done..can sleep..hahahaha

No comments:

Post a Comment