Perl:在运行时打印日志,而不是稍后一次转储所有日志

Perl:在运行时打印日志,而不是稍后一次转储所有日志,perl,unbuffered-output,Perl,Unbuffered Output,我有一个从Jenkins slave运行的Perl脚本。该脚本执行保存在远程框a上的shell脚本。该shell脚本实际上在机器a本身上部署war。Jenkins slave和remote box这两台机器都是CentOS实例 use strict; use warnings; use Cwd; use File::Copy; use Getopt::Long; use File::Basename; use Net::OpenSSH; my ($conf_file, $environment

我有一个从Jenkins slave运行的Perl脚本。该脚本执行保存在远程框a上的shell脚本。该shell脚本实际上在机器a本身上部署war。Jenkins slave和remote box这两台机器都是CentOS实例

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(':', $line);

        $id_file = "/home/ec2-user/.ssh/priv_key";

        $ssh = Net::OpenSSH->new($IP, key_path => $id_file, user => $user);
        $ssh->error and die "Couldn't establish SSH connection: ". $ssh->error;

        printf "\n";
        if (length $wrapper) {      
            printf "Initiating subroutine for executing wrapper on remote 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";
}
使用严格;
使用警告;
使用化学武器;
使用文件::复制;
使用Getopt::Long;
使用File::Basename;
使用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();
亚初始{
$JENKINS_JOB=$ENV{'JOB_NAME'};
$conf_file=“/home/ec2 user/SCM/conf/deploy_build.conf”;
open(FH,“我从node获得了一个解决方案。我可以使用下面的代码实时打印日志,而不是以字符串形式存储输出并在以后转储它

sub exec_wrapper {
    $ssh->system("~/release/$wrapper");
    $ssh->die_on_error("execution of ~/release/$wrapper failed");
}

我对其他方法也持开放态度。

我希望您的意思是不使用Perl脚本,即使用命令行直接从Jenkins slave box调用远程shell脚本。我尝试了,它立即打印输出。:(是的,但幸运的是我得到了。:)