Skip to content

Instantly share code, notes, and snippets.

@tacitochaves
Created June 9, 2014 12:20
Show Gist options
  • Select an option

  • Save tacitochaves/173bd82ef5faf18f7357 to your computer and use it in GitHub Desktop.

Select an option

Save tacitochaves/173bd82ef5faf18f7357 to your computer and use it in GitHub Desktop.
Backup of firewall FwBuilder
#!/usr/bin/env perl
#
# bkp_fwbuilder.pl
#
# This program is responsible for performing the backup of the firewall.
#
# Author: Tácito Chaves
# Contact: (98) 8123 - 8153 / (98) 8857 - 9777
# E-mail: chaves@tchaves.com.br
use strict;
use warnings;
use constant { TMPDIR => '/tmp', };
bkp_fwbuilder();
# check if exist files of backup in the directory with the date current
sub bkp_fwbuilder {
my $date = get_date(localtime);
my @get_list = list_dir(TMPDIR);
if ( grep { m/(bkp)(\d)-$date/ } @get_list ) {
print "There is already a backup digit.";
}
elsif ( grep { m/bkp-$date/ } @get_list ) {
print
"This is the first backup because there is no digit after the bkp.";
}
else {
print "No backup exists, we must create it.";
}
}
# Function to capture data
sub get_date {
my ( undef, undef, undef, $mday, $mon, $year ) = @_;
$year = $year + 1900;
$mon += 1;
if ( length($mon) == 1 ) {
$mon = "0$mon";
}
if ( length($mday) == 1 ) {
$mday = "0$mday";
}
my $today = "$year-$mon-$mday";
return $today;
}
# Function to list the directory contents
sub list_dir {
my $tmp = shift;
opendir( my $dir, $tmp ) or die "Error: $!";
my @list = split( / /, join( " ", readdir($dir) ) );
return @list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment