Logo
  • Home
  • About
  • Services
  • Blogs
  • Career
  • Contact
Logo

The UK's #1 Software Development Company. PodTech IO builds custom software solutions for businesses. Call today for a free consultation

  • Address

    4th Floor, 4 Tabernacle Street London EC2A 4LU
  • Email

    info@podtech.com
  • Contact

    +44 (0) 20 8720 6583

Perl – Execute Command With Timeout

  • Home
  • Perl – Execute Command With Timeout
  • By podtech
  • In Perl

Perl – Execute Command With Timeout

[perl]

my $command_to_check = “$SSH_CON $host $SSH_CMD”;
if (! execute_command($command_to_check)) {
next;
}

sub execute_command($)
{
### Executes a command with timeout
### Returns 0 if fails
### Returns 1 on success

my $command=shift;
my $timeout=30;

eval {
local $SIG{ALRM} = sub{die;};
my($oalarm) = alarm($timeout);
$result=`$command 2>&1`;
if ($? ne 0) {
writeLog(“Error: Command execution failed ($!) – running – $command”);
$error_msg.=”Error: Command execution failed ($!) – running – $command\n\n”;
$returnValue=2;
} else {
writeLog(“Success: $command”);
}
alarm($oalarm);
};

## Result is not defined after timeout duration
## Exit with 0;
if ( ! defined($result) )
{
writeLog(“Error: $command timed-out and failed”);
return 0;
} else {
## Success
return 1;
}
}

[/perl]

Execute CommandExecute Command With TimeoutPerlPerl Execute Command
MYSQL – Replication
Oracle Solaris 11 Overview

Recent Posts

  • DevOps as a Software Development Methodology
  • How Does Spiral Software Development Methodology Work?
  • Waterfall Software Development Methodology And When To Use It
  • What Exactly Is Lean Software Development Methodology?
  • What is Kanban and How Does It Work?

PodTech IO

The UK's #1 Software Development Company. PodTech IO builds custom software solutions for businesses. Call today for a free consultation

Company

  • About
  • Services
  • Contact
  • Blogs
  • Career

Terms

  • Terms & Conditions
  • Privacy Policy

Contact Us

  • ADDRESS

    Headquarter: Tabernacle Street London India: Vi john Tower, Gurgaon, Haryana
  • EMAIL

    info@podtech.com
  • CONTACT

    +44 (0) 20 8720 6583

Copyright ©2023 PodTech IO. All Rights Reserved

Logo