I have a Perl script that runs from Jenkins slave. The script executes a shell script kept on remote box A. This shell script actually deploys war on machine A itself. Both machines, Jenkins slave and remote box are CentOS instances.
use strict;
use warnings;
use Cwd;
use File::Copy;
use Getopt::Long;
use File::Basename;
use Net::OpenSSH;
my ($conf_file, $environment, $doexec, $exec, $job, $dest_file, $user,
+ $host, $IP, $TARGET_SERVER, $JENKINS_JOB, $wrapper, $src_file, $src_
+path, $src_dist_path, $src_full_path, $id_file, $ssh, @array, $line);
init();
sub init {
$JENKINS_JOB = $ENV{'JOB_NAME'};
$conf_file = "/home/ec2-user/SCM/conf/deploy_build.conf";
open (FH, "<", $conf_file) or die "Cannot open < $conf_file: $!";
while (<FH>) {
if ( $_ =~ /\b$JENKINS_JOB\b/ ) {
push @array, $_;
} else {
next;
}
}
foreach $line (@array) {
($job, $src_path, $dest_file, $user, $wrapper) = split(':', $l
+ine);
$id_file = "/home/ec2-user/.ssh/priv_key";
$ssh = Net::OpenSSH->new($IP, key_path => $id_file, user => $u
+ser);
$ssh->error and die "Couldn't establish SSH connection: ". $ss
+h->error;
printf "\n";
if (length $wrapper) {
printf "Initiating subroutine for executing wrapper on rem
+ote machine...\n";
&exec_wrapper;
} else {
printf "*** No wrapper specified ****\n";
}
}
}
sub exec_wrapper {
my ($stdout, $errput) = $ssh->capture2("~/release/$wrapper");
printf "Output: $stdout\n" if $stdout;
die "Error: $errput\n" if $errput;
printf "\n\n\n";
}
Now the issue is that though the program runs fine, it prints output after a while. Whole output is captured in $stdout and then dumped later. Since this job runs as a Jenkins job, the end user has no idea what's going on until the output is dumped. I wanted to print each line as event occurs (runtime) instead of waiting for the whole output to be stored in the variable and dumped later. I did read
this article but i'm not sure whether it applies to my case and if it does, how can i implement it. Just to mention, efficiency is *not* a concern in my scenario. Any help will really be appreciated.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.