Automatic war-packet (Tomcat) installation on a Debian system

last edit 26.09.2011 by Bernhard
The following scripts are very special and surely adapted to our own needs. But maybe it'll help you with similar requirements.

(old) robot-script for automatic war-packet (tomcat) installation on a debian system (special)

(old) robot-script for automatic war-packet (tomcat) installation on a debian system (special)
perl
#!/usr/bin/perl
 
###################################################################
# robot.pl -> Script to automate the deployment of .war files
# by Bernhard Rausch and Mario Kleinsasser
# v1.0
###################################################################
 
###################################################################
# Step 0.5 -> get commandline arguments
###################################################################
 
use Getopt::Std;        #Use the standard perl module for parameter parsing to use -s -t
use Net::FTP;
use DateTime;
 
getopt('stdmcp');        #Get the command line parameters
 
my $Tomcat = $opt_s;       #Set the program internal variable with the parameter value
my $AtTime = $opt_t;       
my $AtDate = $opt_d;
my $Command = $opt_c;
my $Project = $opt_p;
my $AtMinute = 0;        #Inizialize the minute with 0
my $Monitor = $opt_m;       #Get Monitor-Packet parameters (* for all, xy for special packet)
my $CPT = 0;
 
if ( $Command eq "" ) {
 if ( $Tomcat eq "" || $AtTime eq "" ) {  #Check if command line parameters are set
  print "No tomcat/time/date given\n";
  print "./robot.pl -s TOMCAT -t TIME [-d DATE] [-m *|packetname]\n";
  print "Sample: ./robot.pl -s tc6 -t 19:00 -d 16.06.09\n";
  print "Sample: ./robot.pl -s tc6 -t 20:00 -m ii_paket (no war-packet is needed on webdeploy)\n";
  print "./robot.pl -c COMMAND -p PROJECT -t TIME [-d DATE]\n";
  die "Sample: ./robot.pl -c stop -p de_paket -t 19:00 -d 24.12.2010\n";
 }
 else {
  print "Tomcat: $Tomcat\n";
  print "Time: $AtTime\n";
  print "Date: $AtDate\n";
  print "Monitor: $Monitor\n";
 }
}
else {
 if ( $Project eq "" ) {
  print "No project name is given\n";
  print "./robot.pl -s TOMCAT -t TIME [-d DATE] [-m *|packetname]\n";
  print "Sample: ./robot.pl -s tc6 -t 19:00 -d 16.06.09\n";
  print "./robot.pl -c COMMAND -p PROJECT -t TIME [-d DATE]\n";
  die "Sample: ./robot.pl -c stop -p de_paket -t 19:00 -d 24.12.2010\n";
 }
 else {
  if ( $AtTime eq "" ) {
   print "No time name is given\n";
   print "./robot.pl -s TOMCAT -t TIME [-d DATE] [-m *|packetname]\n";
   print "Sample: ./robot.pl -s tc6 -t 19:00 -d 16.06.09\n";
   print "./robot.pl -c COMMAND -p PROJECT -t TIME [-d DATE]\n";
   die "Sample: ./robot.pl -c stop -p de_paket -t 19:00 -d 24.12.2010\n";
  }
  else {
   print "Project: $Project\n";
   print "Command: $Command\n";
   print "Time: $AtTime\n";
 
   if ( $AtDate ne "" ) {
    print "Date: $AtDate\n";
   }
   $CPT = 1;
  }
 }
}
 
 
 
my $time = qx(date +%Y-%m-%d);    #Read the current date from the operating system and store this
chomp($time);        #IMPORTANT remove the CRLF \n escape sequenze from output
$time = $time." $AtTime:00";    #Add the time string to the date
 
 
##############################################################################
# Step 0.9 -> if $CPT = 1 -> just start the given command at the given time
##############################################################################
 
if ( $CPT eq 1 ) {
 my $Uniq = qx(echo $$); 
 
 #Copy dsh-template
 $Output = qx(cp -v /srv/packages/_robot/at_robot_command /tmp/at_robot_command_$Project_$Command_$Uniq);
 #Sample at_robot_command-file
  #dsh -M -g <1> -- '/etc/init.d/tomcat <2>'
 
 print $Output;
 
 #Change dsh-template
 $Output = qx(awk '{gsub("<1>", "$Project"); print > FILENAME}' /tmp/at_robot_command_$Project_$Command_$Uniq);
 $Output = qx(awk '{gsub("<2>", "$Command"); print > FILENAME}' /tmp/at_robot_command_$Project_$Command_$Uniq);
 print $Output;
 
 my $StartTime = qx(date +%H:%M --date "$time $AtMinute minute");  #Compute time and output it as HH:MM to use it with at job
 chomp($StartTime);              #IMPORTANT remove the CRLF \n escape sequenze from output
 
 if ( $AtDate eq "") {
  $Output = qx(at $StartTime -f /tmp/at_robot_command_$Project_$Command_$Uniq); 
 }
 else {
  $Output = qx(at $StartTime $AtDate -f /tmp/at_robot_command_$Project_$Command_$Uniq);
 }
 die "AT-Command for given command was set!";
}
 
##############################################################################
# Step 1.0 -> get .war files from FTP-Server and store them in /tmp/warfiles
#
# Check if folder /tmp/warfiles exist an create if not
##############################################################################
 
$Output = qx(rm -Rf /tmp/warfiles);
print $Output;
 
if ( not (-d "/tmp/warfiles") ) {
 mkdir("/tmp/warfiles",0755);
}
 
 
###################################################################
# Step 2 -> call lftp and transfer files
###################################################################
 
use Cwd;
 
my $wrkdir = getcwd;
 
chdir "/tmp/warfiles";
 
my $ftp_server = "ftp.anywhere.com";
my $ftp_user = "ftpuser";
my $ftp_pw = "FTPPassword";
my $ftp_archive = "/archive";
my $ftp_std_dir = "/tc6";
my $ourDay;
my $ourMonth;
my $ourYear;
 
my $ftp = Net::FTP->new($ftp_server, Debug => 0) or die "Cannot connect to $ftp_server!";
$ftp->login($ftp_user,$ftp_pw) or die "Cannot login to $ftp_server: ", $ftp->message;
 
$ftp->cwd($ftp_archive);
 
$currentDate = DateTime->now;
$ourDay = $currentDate->day;
$ourMonth = $currentDate->month;
$ourYear = $currentDate->year;
 
my $folderDate = sprintf("%4d-%02d-%02d", $ourYear, $ourMonth, $ourDay);
$ftp->mkdir($folderDate);
 
$ftp->cwd($ftp_std_dir);
$ftp->binary();
 
foreach my $ftpfile($ftp->ls) {
 $ftp->get($ftpfile) or die "FTP: Get failed ", $ftp->message;
 print "Get file $ftpfile from FTP.\n";
 $ftp->put($ftpfile,"$ftp_archive/$folderDate/$ftpfile") or die "FTP: Put to archive failed ", $ftp->message;
 print "Put file $ftpfile to FTP archive.\n";
 $ftp->delete($ftpfile) or die "FTP: Delete failed ", $ftp->message;
 print "Delete file $ftpfile from FTP.\n";
}
 
$ftp->quit;
 
chdir $wrkdir;
 
###################################################################
# Step 2.5 -> if the monitor-packet should be installed
###################################################################
 
if ( $Monitor ne "") {
 if ( $Monitor eq "all") {
 
 }
 else {
  my $RepVer = qx(wget -q http://own-debian-repo.anywhere.com:10000/pool/stable/h/prefix-ii-monitor/ -O /tmp/out && sed -ne '10p' /tmp/out | awk -F \"\\\"\" {'print \$8'} | awk -F \"_\" {'print \$2'} );
  $RepVer =~ s/\n//g;
  my $WebdepVer = "NoNewPacket";
 
  opendir(DIR, "/tmp/warfiles") || die "$Verzeichnis: $!";                #Open directory
  my @Dateien = readdir(DIR);
  foreach(@Dateien) {         #Main Loop
   if($_ =~ /.+\.war*/) {
    my $Length = length($_);                                                #Get length of .war-file
    my $Cutted = lc(substr($_, 0, ($Length-4)));                            #Cut '.war' from .war-file & to lower case
    @Woerter = split(/-/,$Cutted);                                          #Split .war-file by '-'
    $WebdepVer = $Woerter[2];                                                  #Paket-Version like '02.03.010'
   }
  }
 
  print "Repository Version: $RepVer\n";
  print "WebDeploy Version: $WebdepVer\n";
 
  if ($WebdepVer eq "NoNewPacket") {
   #print "NoNewPacket";
   if ($RepVer ne "") {
    #print "AT-JOB";
    #Copy dsh-template
    $Output = qx(cp -v /srv/packages/_robot/at_robot /tmp/warfiles/monitor+$Monitor.at);
    print $Output;
    #Sample at_robot-file
     #dsh -M -g <1> -- 'apt-get update && apt-get clean && apt-get -y install hns-<2>'
 
    #Change dsh-template
    $Output = qx(awk '{gsub("<1>", "$Monitor"); print > FILENAME}' /tmp/warfiles/monitor+$Monitor.at);
    $Output = qx(awk '{gsub("<2>", "ii-monitor"); print > FILENAME}' /tmp/warfiles/monitor+$Monitor.at);
    print $Output;
 
    #Make at-job for auto-install
    my $StartTime = qx(date +%H:%M --date "$time $AtMinute minute"); #Compute time and output it as HH:MM to use it with at job
    chomp($StartTime);             #IMPORTANT remove the CRLF \n escape sequenze from output
 
    if ( $AtDate eq "") {
     $Output = qx(at $StartTime -f /tmp/warfiles/monitor+$Monitor.at); 
    }
    else {
     $Output = qx(at $StartTime $AtDate -f /tmp/warfiles/monitor+$Monitor.at);
    }
 
    print $AtMinute."\n";
    print "****************************************************************************************************************\n";
   }   
  }
  else {
   print "No Action made!!\n";
   print "****************************************************************************************************************\n";
  }
 }
} else {
 
###################################################################
# Step 3 -> Loop to process war files in /tmp/warfiles
###################################################################
 
 opendir(DIR, "/tmp/warfiles") || die "$Verzeichnis: $!";    #Open directory
 my @Dateien = readdir(DIR);            #Read Files
 foreach(@Dateien) {                 #Main Loop
  if($_ =~ /.+\.war*/) {            #Process only if .war-file
   my $Length = length($_);          #Get length of .war-file
   my $Cutted = lc(substr($_, 0, ($Length-4)));     #Cut '.war' from .war-file & to lower case
   print "$_\n";        
   @Woerter = split(/-/,$Cutted);      #Split .war-file by '-'
   print "$Woerter[0]\n";        #Paket-Name like 'strabbm'
   print "$Woerter[1]\n";        #Paket-Locale like 'ii'
   print "$Woerter[2]\n";        #Paket-Version like '02.03.010'
 
   $Output = qx(cp -vR /srv/packages/_robot/$Tomcat\_prefix-locale-template /tmp/warfiles/prefix-$Woerter[1]-$Woerter[0]); #Copy template
   print $Output;
 
   #Search & Replace CONTROL,PREINST,PRERM,POSTINST
   $Output = qx(awk '{gsub("prefix-locale-template", "prefix-$Woerter[1]-$Woerter[0]"); print > FILENAME}' /tmp/warfiles/prefix-$Woerter[1]-$Woerter[0]/DEBIAN/control);
   print $Output;
   $Output = qx(awk '{gsub("00.00.000", "$Woerter[2]"); print > FILENAME}' /tmp/warfiles/prefix-$Woerter[1]-$Woerter[0]/DEBIAN/control);
   print $Output;
   #control-file sample
    #Package: prefix-locale-template
    #Section: base
    #Priority: extra
    #Maintainer: fritz the cat
    #Architecture: all
    #Version: 00.00.000
    #Description: prefix-locale-template application for rollout on "fritz the cat" tomcat-webservers
 
   $Output = qx(awk '{gsub("template", "$Woerter[0]"); print > FILENAME}' /tmp/warfiles/prefix-$Woerter[1]-$Woerter[0]/DEBIAN/preinst /tmp/warfiles/prefix-$Woerter[1]-$Woerter[0]/DEBIAN/prerm /tmp/warfiles/prefix-$Woerter[1]-$Woerter[0]/DEBIAN/postinst);
   print $Output;
   #Sample preinst-file
    ##!/bin/sh -e
    #VERSION="00.00.000"
    #WEBAPPS="/opt/prefix-tomcat/webapps/prefix-tomcat_i01_3001"
    #WORK="/var/tmp/tomcat/prefix-tomcat_i01_3001/work"
    #CONF="/opt/prefix-tomcat/server/prefix-tomcat_i01_3001/conf"
    #NAME="template"
    #echo " "
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "----------------           PREINST       ----------------------"
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "BEGIN INSTALLATION $NAME $VERSION"
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "Stopping Tomcat ..."
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #/etc/init.d/prefix-tomcat_i01_3001 stop
    #echo " "
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "Delete all files in Tomcat Work-Folder ..."
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #rm -Rf $WORK/*
    #rm -Rf $CONF/Catalina
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "Delete old $NAME.war & $NAME folder ..."
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #rm -Rf $WEBAPPS/$NAME*
    #echo " "
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "Copy new $NAME.war & server.xml ..."
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "----------------           PREINST       ----------------------"
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
 
   $Output = qx(awk '{gsub("locale", "$Woerter[1]"); print > FILENAME}' /tmp/warfiles/prefix-$Woerter[1]-$Woerter[0]/DEBIAN/preinst /tmp/warfiles/prefix-$Woerter[1]-$Woerter[0]/DEBIAN/prerm /tmp/warfiles/prefix-$Woerter[1]-$Woerter[0]/DEBIAN/postinst);
   print $Output;
   #Sample postinst-file
    ##!/bin/sh -e
    #VERSION="00.00.000"
    #WEBAPPS="/opt/prefix-tomcat/webapps/prefix-tomcat_i01_3001"
    #NAME="template"
    #echo " "
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "----------------          POSTINST       ----------------------"
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "END Installation $NAME $VERSION"
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "Changing rights on $NAME.war & server.xml..."
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #if [ -e $WEBAPPS/$NAME.war ];    # NOTE [with spaces]
    # then
    #   chown tomcat.tomcat $WEBAPPS/$NAME.war
    # fi
    #
    #if [ -d $WEBAPPS/$NAME ];    # NOTE [with spaces]
    # then
    #   chown -R tomcat.tomcat $WEBAPPS/$NAME
    # fi
    #echo " "
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "Starting Tomcat ..."
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #sleep 5
    #/etc/init.d/prefix-tomcat_i01_3001 start
    #ps -ef | grep tomcat
    #echo " "
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "INSTALLATION READY"
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "----------------          POSTINST       ----------------------"
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
 
   $Output = qx(awk '{gsub("00.00.000", "$Woerter[2]"); print > FILENAME}' /tmp/warfiles/prefix-$Woerter[1]-$Woerter[0]/DEBIAN/preinst /tmp/warfiles/prefix-$Woerter[1]-$Woerter[0]/DEBIAN/prerm /tmp/warfiles/prefix-$Woerter[1]-$Woerter[0]/DEBIAN/postinst);
   print $Output;
   #Sample postinst-file
    ##!/bin/sh -e
    #VERSION="00.00.000"
    #WEBAPPS="/opt/prefix-tomcat/webapps/prefix-tomcat_i01_3001"
    #WORK="/var/tmp/tomcat/prefix-tomcat_i01_3001/work"
    #CONF="/opt/prefix-tomcat/server/prefix-tomcat_i01_3001/conf"
    #NAME="template"
    #echo " "
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "----------------            PRERM        ----------------------"
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "Stopping Tomcat ..."
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #/etc/init.d/prefix-tomcat_i01_3001 stop
    #echo " "
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "Deleting all files in Tomcat Work-Folder ..."
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #rm -Rf $WORK/*
    #rm -Rf $CONF/Catalina
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "Deleting old $NAME.war & $NAME folder ..."
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #rm -Rf $WEBAPPS/$NAME*
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    #echo "----------------            PRERM        ----------------------"
    #echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
 
   #For different Tomcats do different things
   if ($Tomcat eq "tc5"){
   #Move .war-file to Paket-Directory
     $Output = qx(mv -v /tmp/warfiles/$_ /tmp/warfiles/prefix-$Woerter[1]-$Woerter[0]/usr/local/jakarta-tomcat-5.0.28/webapps/$Woerter[0].war); #Copy template
     print $Output;
   }
   else {
   #Move .war-file to Paket-Directory
    #if ($Woerter[1] eq "ch" || $Woerter[1] eq "ru" || $Woerter[1] eq "pl" || $Woerter[1] eq "cz" || $Woerter[1] eq "se" || $Woerter[1] eq "sk") {
    if ($Woerter[0] eq "tb" || $Woerter[0] eq "rk" || $Woerter[0] eq "awp") {
     $Output = qx(mv -v /tmp/warfiles/$_ /tmp/warfiles/prefix-$Woerter[1]-$Woerter[0]/opt/prefix-tomcat/webapps/prefix-tomcat_i01_3001/$Woerter[0]-$Woerter[1].war); #Copy template
     print $Output;    
    }
    else {
     $Output = qx(mv -v /tmp/warfiles/$_ /tmp/warfiles/prefix-$Woerter[1]-$Woerter[0]/opt/prefix-tomcat/webapps/prefix-tomcat_i01_3001/$Woerter[0].war); #Copy template
     print $Output;
    }
 
   }
 
   #Copy package.sh Script to /tmp Folder
   $Output = qx(cp -v /srv/packages/_robot/package.sh /tmp/warfiles);
   print $Output;
 
   #Run package.sh and create .deb
   $Output = qx(/tmp/warfiles/package.sh prefix-$Woerter[1]-$Woerter[0]);
   print $Output;
 
   #Move .deb to Repository
   $Output = qx(reprepro -C stable includedeb prefix /tmp/warfiles/prefix-$Woerter[1]-$Woerter[0].deb);
   print $Output;
 
   #Copy dsh-template
   $Output = qx(cp -v /srv/packages/_robot/at_robot /tmp/warfiles/$Woerter[1]-$Woerter[0].at);
   print $Output;
   #Sample at_robot-file
    #dsh -M -g <1> -- 'apt-get update && apt-get clean && apt-get -y install hns-<2>'
 
 
   #Change dsh-template
   $Output = qx(awk '{gsub("<1>", "$Woerter[1]_$Woerter[0]"); print > FILENAME}' /tmp/warfiles/$Woerter[1]-$Woerter[0].at);
   $Output = qx(awk '{gsub("<2>", "$Woerter[1]-$Woerter[0]"); print > FILENAME}' /tmp/warfiles/$Woerter[1]-$Woerter[0].at);
   print $Output;
 
   #Make at-job for auto-install
   my $StartTime = qx(date +%H:%M --date "$time $AtMinute minute");  #Compute time and output it as HH:MM to use it with at job
   chomp($StartTime);              #IMPORTANT remove the CRLF \n escape sequenze from output
 
   if ( $AtDate eq "") {
    $Output = qx(at $StartTime -f /tmp/warfiles/$Woerter[1]-$Woerter[0].at); 
   }
   else {
    $Output = qx(at $StartTime $AtDate -f /tmp/warfiles/$Woerter[1]-$Woerter[0].at);
   }
 
   $AtMinute+=3;
   print $AtMinute."\n";
 
   print "****************************************************************************************************************\n";
  }
 }
}

(new) robot-script for automatic war-packet (tomcat) installation on a debian system (special)

(new) robot-script for automatic war-packet (tomcat) installation on a debian system (special)
perl
#!/usr/bin/perl
 
###################################################################
# robot.pl -> Script to automate the deployment of .war files
# by Bernhard Rausch and Mario Kleinsasser
# V2.0
###################################################################
 
use Getopt::Std;                                  #Use the standard perl module for parameter parsing to use -s -t
use Net::FTP;
use DateTime;
 
#-------------------
# Parameter options
#-------------------
 
getopt('o');
 
my $ou = $opt_o;
my $time = "";
$time = $opt_t;
my $date = "";
$date = $opt_d;
 
#-------------------
# Program variables
#-------------------
 
my $ftp_server = "ftp.anywhere.com";
my $ftp_user = "ftpuser";
my $ftp_pw = "FTPPassword";
my $ftp_std_dir = "/tc6";
my $nantan_url = "http://nantan.anywhere.com:8080/nantan/ResourceData?response=ipv4&ou=";
 
my $output = "";
 
#-------------------
# MAIN - START
#-------------------
 
 
if ( $ou eq ""){
 die ( "Define OU parameter!\n" );
}
elsif ( $ou eq "all" ) {
 
 my @packet_list = getFTPPackages();
 
 foreach my $packet (@packet_list) {
 
  my $ou_server = getOUServers( $packet );
 
  if ( $ou_server eq "" ) {
                        die ( "Packet \"$packet\" on FTP found but no corresponding OU found!\n" );
                }
  else {
   $output .= $ou_server;
  }
 }
 
}
else {
 
 my @packet_list = getFTPPackage( $ou );
 my $packet = @packet_list[0];
 
 if ( $packet eq "" ) {
  die ( "No packet for \"$ou\" found on FTP!\n" );
 }
 else {
  my $ou_server = getOUServers( $packet );
 
  if ( $ou_server eq "" ) {
   die ( "Packet \"$packet\" on FTP found but no OU with name \"$ou\" found!\n" );
  }
  else {
 
   makeATJob( $ou_server, $time, $date );
 
   $output = $ou_server;
  }
 }
 
}
 
#print $output;
 
 
 
 
#-------------------
# MAIN - END
#-------------------
 
 
 
#-------------------
# Functions
#-------------------
 
 
sub getOUServers {
 my $packet = shift;
 
 my $ret_val = "";
 
 if($packet =~ /.+\.war*/) {
  my $h_length = length($packet);                                                #Get length of .war-file
                my $h_cutted = lc(substr($packet, 0, ($h_length-4)));                  #Cut '.war' from .war-file & to lower case
                @war_packet = split(/-/,$h_cutted);                                    #Split .war-file by '-'
                #print $war_packet[2]."\n";   -> Package-Version like '02.03.010'
    #print $war_packet[0]."\n";   -> Package-Name
    #print $war_packet[1]."\n";   -> Package-Country
 }
 
 my $h_url = $nantan_url.$war_packet[0]."-".$war_packet[1];
 $ret_val = qx( curl -s '$h_url' );
 
 return $ret_val;
}
 
sub getFTPPackages {
 
 my $ftp = Net::FTP->new($ftp_server, Debug => 0) or die "Cannot connect to $ftp_server!"; 
 $ftp->login($ftp_user,$ftp_pw) or die "Cannot login to $ftp_server: ", $ftp->message;
 
 $ftp->cwd($ftp_std_dir);
 
 my @packet_list = $ftp->ls("*.war");
 $ftp->quit;
 
 return @packet_list;
}
 
sub getFTPPackage {
 
 my $ou = shift;
 
 my $ftp = Net::FTP->new($ftp_server, Debug => 0) or die "Cannot connect to $ftp_server!"; 
 $ftp->login($ftp_user,$ftp_pw) or die "Cannot login to $ftp_server: ", $ftp->message;
 
 $ftp->cwd($ftp_std_dir);
 
 my @packet_list = $ftp->ls("$ou*.war");
 $ftp->quit;
 
 return @packet_list;
}
 
sub makeATJob {
 my $server = shift;
 my $AtTime = shift;
 my $AtDate = shift;
 
 my $ourHour;
 my $ourMinute;
 my $ourDay;
 my $ourMonth;
 my $ourYear;
 
 $currentDate = DateTime->now;
 
 if ($AtTime eq ""){
  $ourHour = 19;
  $ourMinute = 00;
 } else {
  @ourTime = split(/:/,$AtTime);
  $ourHour = @ourTime[0];
  $ourMinute = $ourTime[1];  
 }
 
 if ($AtDate eq ""){
  $ourDay = $currentDate->day;
  $ourMonth = $currentDate->month;
  $ourYear = $currentDate->year;
 } else {
  @ourDate = split(/./,$AtDate);
  $ourDay = $ourDate[0];
  $ourMonth = $ourDate[1];
  $ourYear = $ourDate[2]; 
 }
 
 $targetDate = DateTime->new(
  year       => $ourYear,
  month      => $ourMonth,
  day        => $ourDay,
  hour       => $ourHour,
  minute     => $ourMinute,
 );
 
 #at 19:00 08.07.2011
 
 my $execDT = sprintf "%02d:%02d %s", $targetDate->hour, $targetDate->minute, $targetDate->dmy('.');
 print $execDT;
 
 
 my $output = qx(
  at $execDT <<EOF
  ssh root\@10.200.2.96 -c 'w'
  EOF
   );
 
 
}

Comments

Popular posts from this blog

PHPMixBill V5 mikrotik Billing Solutions

How to install Asterisk and A2billing on Ubuntu Server 12.04LTS

odbcinst: SQLGetPrivateProfileString failed with