Created
July 2, 2015 22:44
-
-
Save alja/30e03e1d517f678e09f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use vars qw ($FW_ENABLED); | |
use Date::Parse; | |
use Getopt::Long; | |
sub convert_time { | |
my $time = shift; | |
my $days = int($time / 86400); | |
$time -= ($days * 86400); | |
my $hours = int($time / 3600); | |
$time -= ($hours * 3600); | |
my $minutes = int($time / 60); | |
my $seconds = $time % 60; | |
$days = $days < 1 ? '' : $days .'d '; | |
$hours = $hours < 1 ? '' : $hours .'h '; | |
$minutes = $minutes < 1 ? '' : $minutes . 'm '; | |
$time = $days . $hours . $minutes . $seconds . 's'; | |
return $time; | |
} | |
################################################################################ | |
# MAIN | |
################################################################################ | |
if (@ARGV < 3) { | |
print ("usage: ./VipLive.pl --dirLive=<path> --dirVIP=<path> --shedule=<path>\n"); | |
print ("\nexample of a shedule file content:\n"); | |
print "01 Jul 2015 00:00:00 / 01 Jul 2015 14:00:00\n"; | |
print "02 Jul 2015 15:00:00 / 02 Jul 2015 15:30:00\n"; | |
print "25 Dec 2015 00:00:00 / 01 Jan 2016 00:00:00\n"; | |
exit 1; | |
} | |
my $scheduleFile='VIPinterval.txt'; | |
my $dirLive="/home/vis/FireworksOnline"; | |
my $dirVIP="/home/vis/FireworksOnlineVIP"; | |
my $result = GetOptions ("dirLive=s" => \$dirLive, | |
"dirVIP=s" => \$dirVIP, | |
"schedule=s" =>\$scheduleFile); | |
if ( ! -e $dirLive){die "dirLive $dirLive is not valid path $!"}; | |
if ( ! -e $dirVIP) {die "dirVIP $dirVIP is not valid path $!"}; | |
do "$dirLive/bin/fw-config.txt"; | |
my $liveCurrentlyActive=$FW_ENABLED; | |
do "$dirVIP/bin/fw-config.txt"; | |
my $vipCurrentlyActive=$FW_ENABLED; | |
my $isVIP=0; | |
open(INFO, $scheduleFile) or die("Could not open file."); | |
foreach my $line (<INFO>) { | |
if ($line =~ /(.+)\/(.+)/) { | |
chomp $line; | |
my $t1 = "$1"; chomp $t1; | |
my $t2 = $2; chomp $t2; | |
my $f1 = str2time($t1); | |
my $f2 = str2time($t2); | |
my $n = time; | |
my $td1 = -$n + $f1; | |
my $td2 = -$n + $f2; | |
if (($td1 > 0) && ($td2 > 0)) { | |
printf("%s ==> sheduled [%s] - [%s]\n", $line, convert_time($td1), convert_time($td2)); | |
} | |
elsif ( $td2 > 0 && $td1 < 0) { | |
printf("%s ==> active, expires in [%s] \n", $line, convert_time($td2)); | |
$isVIP=1; | |
last; | |
} | |
else { | |
print("$line ==> expired\n"); | |
} | |
} | |
} | |
# stop what should have been stopped | |
if ($isVIP) | |
{ | |
if ($liveCurrentlyActive == 0) { system("$dirVIP/bin/fireworksOnlineSystem start $dirVIP"); } | |
if ($liveCurrentlyActive == 1) { system("$dirLive/bin/fireworksOnlineSystem stop $dirLive"); } | |
} | |
else { | |
if ($vipCurrentlyActive == 1) { system("$dirVIP/bin/fireworksOnlineSystem stop $dirVIP"); } | |
if ($liveCurrentlyActive == 0) { system("$dirLive/bin/fireworksOnlineSystem start $dirLive");} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment