Wednesday, February 05, 2014

perl command line arguments

#!/usr/bin/perl -w

use strict;
use Getopt::Long;
use utils qw( &usage );
my($host,$port,$user,$password,$file,$opt_w,$opt_c) = ("",22,"","","","","","","","");

Getopt::Long::Configure('bundling', 'no_ignore_case');
GetOptions
("H|host=s"     => \$host,
 "p|port=s"     => \$port,
 "U|user=s"     => \$user,
 "P|password=s" => \$password,
 "F|file=s"     => \$file,
 "w|warning=s"  => \$opt_w,
 "c|critical=s" => \$opt_c,
 );


($host) ||  usage("Host not specified\n");
($user) ||  usage("SFTP Username not specified\n");
($password) || usage("SFTP password not specified\n");
($file) ||  usage("File to upload and download not specified\n");
($opt_w) || usage("Warning threshold not specified\n");
($opt_c) || usage("Critical threshold not specified\n");

No comments: