I need something like this:
timeout -k 4 cat file | myscript.sh
but i get this error:
timeout: invalid time interval ‘cat’
Try 'timeout --help' for more information.
I want to pass stdin to myscript.sh, and kill it after 4s of execution.
bashtimeout
I need something like this:
timeout -k 4 cat file | myscript.sh
but i get this error:
timeout: invalid time interval ‘cat’
Try 'timeout --help' for more information.
I want to pass stdin to myscript.sh, and kill it after 4s of execution.
Best Answer
Upon reading the output of
timeout --help
(as suggested by the output in your question), I found that you are not using the proper arguments for thetimeout
command.The format of the command is:
timeout [OPTION] DURATION COMMAND [ARG]...
And the
-k
option also takes aDURATION
argument. So when using-k
,there must be twoDURATION
arguments.So a proper format could be:
timeout -k 6 4 cat file | myscript.sh
It is not going to change much though.
cat
doesn't block theTERM
signal, so sending aKILL
signal isn't necessary. And even if you do killcat
, that is no guarantee that the script terminates. It just means the script will getEOF
, in case it tries to read any more fromstdin
.You are probably better off putting a timeout on the script instead of the
cat
command.