I am working on a old Solaris node which does not have coreutils(timeout) tool installed. I am trying to print output of three bash commands separated by "-" x 80
chars. One of the command is having bad rep of taking very long time and I need to timeout that command and print the remaining output. I am trying to use alarm shift
but this does not help.
I need to keep the command as a one liner as I need to use this command in ansible's shell module. Can someone please help.
If I run the different CMDn
commands on bash terminal, it returns following output:
This is
from CMDn
Where n is 0 to 3.
When I run following perl command it returns :
perl -sanle 'BEGIN{$sep=("-"x80)."\n"; \
print "$sep $CMD0\n $sep $CMD1\n $sep $CMD2\n $sep $CMD2flt\n";exit}' \
-- -CMD0="$(CMD0)" -CMD1="$(CMD1 -q all)" -CMD2="$(CMD2)" -CMD2flt="$(CMD3)"
--------------------------------------------------------------------------------
This is
from CMD0
--------------------------------------------------------------------------------
This is
from CMD1
--------------------------------------------------------------------------------
This is
from CMD2
--------------------------------------------------------------------------------
This is
from CMD3
Sometimes, CMD3
takes very long time and I need to timeout it and proceed with the print of CMD0
, CMD1
, CMD2
. I tried this command but this does not help as it is not timing out and it will timeout for all the outputs. In this example I am using sleep 15 && CMD3
as CMD3 and timeout as 10 , but this does not helped. I followed this post Timeout command on Mac OS X?
perl -sanle 'BEGIN{alarm shift; $sep=("-"x80)."\n"; \
print "$sep $CMD0\n $sep $CMD1\n $sep $CMD2\n $sep $CMD2flt\n";exit}' \
-- -CMD0="$(CMD0)" -CMD1="$(CMD1 -q all)" -CMD2="$(CMD2)" -CMD2flt="$(sleep 15 && CMD3)" 10
Expecting following output if (for example) CMD3
is timing out.
--------------------------------------------------------------------------------
This is
from CMD0
--------------------------------------------------------------------------------
This is
from CMD1
--------------------------------------------------------------------------------
This is
from CMD2
--------------------------------------------------------------------------------
Null or blank or any intuitive text