How can I time out an input/output redirection in Linux?

ndarkness :

I was wondering whether or not it is possible to time out an input/output redirection in Linux.

Meaning that I would like to redirect certain input/output to a file just for a time span of 2s for instance.

In a practical case, I am looking to cat the tty0 to a file only during 2s

cat /dev/tty0 >> ~/uart.txt

How can I achieve this?

Thanks

William Pursell :

On most linux, you should have access to timeout:

timeout 2 cat /dev/tty >> ~/uart.txt

This will send a SIGTERM after 2 seconds. If you want a different signal, use -s. If you want to follow up with SIGKILL, use -k. man timeout for details.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=174466&siteId=1
Recommended