Perl - check_ssl_cert.pl
2011.09.01. 10:45
#!/usr/bin/perl
####
##
##
## ## $JOEY
#### 2011.09.01.
use strict;
################################################
# | DESCRIPTION:
# | Check the remaining days from ssl-certificate
# | USAGE:
# | check_ssl_cert(<Cert_Path>);
# | RESULTS:
# | Remaining days
sub check_ssl_cert($) {
my $cert_path = shift;
my @zero_date = split(' ',`openssl x509 -in $cert_path -text|grep 'Not '|tail -n1`);
my %months = ('Jan'=>1,'Feb'=>2,'Mar'=>3,'Apr'=>4,'May'=>5,'Jun'=>6,'Jul'=>7,'Aug'=>8,'Sep'=>9,'Oct'=>10,'Nov'=>11,'Dec'=>12);
my @month_days = (0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365);
my $zero_day = $zero_date[4];
my $zero_month = $months{$zero_date[3]};
my $zero_year = $zero_date[6];
my $remaining_days = ((($zero_year-((localtime(time))[5]+1900))*$month_days[12]) + ($month_days[$zero_month-1])-($month_days[(localtime(time))[4]]) - ((localtime(time))[3]) + $zero_day) + 1;
return $remaining_days;
}
# |
################################################
# e.g.:
# print check_ssl_cert("/usr/local/apache2/ssl/*.crt")."\n";
Bash - one-liner - Filesystem-check
2011.09.01. 08:40
# Filesystems over 80%
M=80;df -Ph|while read L;do S=`echo $L|awk '{print $5}'|sed 's/\(.*\)./\1/'`; if [ "$S" != "Use" ];then if [ $S -ge $M ] ;then echo $L;fi;else echo $L;fi;done
Perl - test_host_availability.pl
2011.09.01. 07:37
#!/usr/bin/perl
####
##
##
## ## $JOEY
#### 2011.08.31.
use strict;
use Net::Ping;
################################################
# | DESCRIPTION:
# | Test if host is reachable
# | USAGE:
# | test_host_availability(<HOSTNAME>);
# | RESULTS:
# | 0 : HOST isn't reachable
# | 1 : HOST is reachable
sub test_host_availability($) {
my $thost = shift;
my $tping = new Net::Ping("tcp");
$tping->{port_num}=22;
my $result = $tping -> ping($thost,2); # Usage: ping(host,timeout)
return $result; # Return 0 if host isn't reachable, return 1 if host is reachable
}
# |
################################################
# e.g.:
# my $host = "hostname";
# chomp($host);
# if (test_host_availability($host)) {
# print "$host is reachable\n";
# } else {
# print "$host is not reachable\n";
# }
Perl - current_ISODATE.pl
2011.09.01. 07:20
#!/usr/bin/perl
####
##
##
## ## $JOEY
#### 2011.08.31.
use strict;
################################################
# | DESCRIPTION:
# | Get the current date in YYYY-MM-DD format or the time in HH:MM:SS format
# | USAGE:
# | my $DATE = current_ISODATE([D,T]);
# | e.g. print current_ISODATE("D")." ".current_ISODATE("T")."\n";
# | RESULTS:
# | YYYY-MM-DD or HH:MM:SS
sub current_ISODATE($) {
my $output_type = shift;
my $ISOdate;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
$year += 1900;
$mon += 1;
if ($output_type eq "D") {
$ISOdate = sprintf "%04d-%02d-%02d", $year, $mon, $mday;
} elsif ($output_type eq "T") {
$ISOdate = sprintf "%02d:%02d:%02d", $hour, $min, $sec;
}
return $ISOdate;
}
# |
################################################
# e.g.:
# print current_ISODATE("D")." ".current_ISODATE("T")."\n"