© 2023 PodTECH IO
All rights reserved.

Get in Touch

Perl

Perl – Execute Command With Timeout

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 ($? […]