Comments on Linux timeout Command Explained for Beginners (with Examples)

Sometimes, when you execute a command in Linux, you might want to run it for a set amount of time. There exists a command line utility - timeout - that's specifically developed for this purpose.

1 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: Pete

A non-trivial example is to record TV from an HDHR network tuner.  These tuners have DLNA support which is effectively an http server.  TV broadcasts never end, so to stop "recording" the wget needs to be limited.

$TIMEOUT ${DUR}m wget -O \ "$TITLE-$DATE-$CH.ts"  $URL$CH$TRANS

I'm using variables for commands, the recorded duration, and the URL to the specific show to be recorded, but you get the idea.

CH="$1"   # digital channel 2.1, 2.2, etc...DUR="$2"  # in minutesTITLE="$3" # for the filenameDATE=`date "+%y%m%d-%H%M%S"`WGET=/usr/bin/wgetTIMEOUT=/usr/bin/timeoutFFMPEG=/usr/bin/ffmpegURL=http://hdhr4:5004/auto/v

Basically, it is just a limited time on the download which becomes a TV recording in mpeg2 TS format.

Timeout makes this possible.