/  10
 
#!/usr/bin/perl -w########################################################################################## Name: vprr_file_remover.pl## Revision: 0.01 2009/02/12# Initial Revision.#########################################################################################use strict;use warnings;use Getopt::Long qw(GetOptions);use Pod::Usage qw(pod2usage);use File::Basename qw(basename);use File::Copy qw(move);use DBI;use IO::Handle;use Data::Dumper;## Turn on autoflush#BEGIN { $| = 1 }## Make %ENV safer#$ENV{'PATH'} = '/bin:/usr/bin';delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};## Clear possible tainted script name#$0=basename($0);{no locale;($0)= ($0 =~ m/^([\w\.\-]+)/);}## Globals#use vars qw/ %opt %config @error_msgs /;
 
my %opt = ();my %config = ();my @error_msgs = ();our $VERSION= 0.01;###################################################################################################### The usage_error() subroutine is used to print this script usage error.#####################################################################################################sub usage_error {my $message = shift;print STDERR "USAGE ERROR: $message\n" if defined($message);exit 1;}###################################################################################################### The init() subroutine is used to set up database connection and capture any of the options# from the command line.#####################################################################################################sub init {my $config = shift;## Parse the command line for options#GetOptions('verbose|n' => \$opt{'n'},'count_run|c' => \$opt{'c'},'ifile|f=s' => \$opt{'f'},'vprr_dir|d=s' => \$opt{'d'},'target_dir|t=s' => \$opt{'t'},'version|v' => \$opt{'v'},'help|h' => \$opt{'h'}) or usage_error("Failed to process command line options.");## Print VERSION number for this script and exit if 'version' option is detected.#do { print STDOUT "$0 Version $VERSION\n"; exit(0); } if $opt{'v'};#
 
# Print perldoc for this script and exit if 'help' option is detected.#pod2usage({-exitval => 0, -verbose => 2}) if $opt{'h'};## Check --test option.#$config->{'count_run'} = !defined($opt{'c'}) ? 0 : 1;usage_error("The -ifile option is required.") if !defined($opt{'f'});## Check if ifile option is provided.#usage_error("The -ifile option is required.") if !defined($opt{'f'});$config->{'ifile'} = $opt{'f'};$config->{'ifile'} =~ s/\s//g;## Check Input file#usage_error("Input file $config->{'ifile'} does not exist.") if !-e $config->{'ifile'};## Default VPRR directory to /ftp/edgar/vprr if --vprr_dir option is not provided.#$config->{'vprr_dir'} = !$opt{'d'} ? '/ftp/edgar/vprr' : $opt{'d'};## Validate the VPRR directory#usage_error("Directory $config->{'vprr_dir'} does not exist.") if !-d $config->{'vprr_dir'};usage_error("Directory $config->{'vprr_dir'} is not accessable.")if !opendir(DIR, $config->{'vprr_dir'});closedir(DIR);## Set up the output filename#my ($mday, $mon, $year) = (localtime(time()))[3,4,5];$year += 1900;$mon++;$config->{'outfile'} = basename($0, '.pl') . '.' .sprintf("%04d-%02d-%02d", $year, $mon, $mday) .'.out';if (!$config->{'count_run'}) {

Share & Embed

More from this user

Add a Comment

Characters: ...