G. Pape


tryto - tries to run a command limited by a timeout or number of tries, can be used to run as multilog(8) processor.


tryto [ -pv ] [ -t sec ] [ -k ksec ] [ -n tries ] prog


prog consist of one or more arguments.

tryto runs and watches prog, feeding its standard input to prog's standard input. If prog exits with an error code other then 0, tryto runs prog again after sleeping one second.

If the number of retries reaches the maximal number of tries, tryto prints an error message and gives up.

If the timeout sec seconds is reached and prog is still running, tryto sends a TERM signal to prog, waits ksec seconds for prog to terminate, then sends a KILL signal if prog still is there, and exits as soon as possible.

The main purpose of tryto is to run as multilog(8) processor (see below). Without the -p option, tryto does just a subset of what timelimit(8) from Peter Pentchev provides.


verbose. Print verbose messages to stderr.
processor. Use this option if you run tryto as a multilog(8) processor (see below).
-t sec
timeout. Set the timeout to send TERM to prog to sec seconds. Default is 180.
-k ksec
kill timeout. Set the timeout to send KILL to prog to ksec seconds. Default is 5.
-n tries
Set the maximal number of tries to tries. If prog has crashed, tryto tries to rewind stdin to the beginning using lseek(2) before starting prog again. Default is 5.

Multilog Processor

If tryto sees the -p option, tryto runs as a multilog(8) processor, making use of filedescriptors 4 and 5:

Before starting prog, tryto moves the filedescriptor 5 to 2, so all error messages from tryto and prog will be saved in multilog(8)'s state to be processed on the next run of tryto -p.

After starting prog, tryto first feeds all data it reads from filedescriptor 4 into prog's standard input, then all data from filedescriptor 0.

If prog fails by timeout sec seconds or maximal number of tries, tryto prints all data from standard input to standard output, an error message to standard error and exits with 0.

Exit Codes

If tryto itself fails, it returns 111.

If tryto runs as a multilog(8) processor, tryto returns 0 in all other cases.

If prog was run successfully, tryto returns 0.

If prog failed by timeout, tryto returns 100.

If prog failed by maximal number of tries, tryto returns the last exit code from prog.

See Also

multilog(8), socklog(8), uncat(1), lseek(2), timelimit(8)



Gerrit Pape <pape@smarden.org>

Table of Contents