Shell tips

OpenBSD 7.0 comes with a new utility named timeout to run a command and stop it after an user defined time. The is available for full information. While it was possible to achieve this in shell using a child process sleeping for some time and stopping the main process if it wasn't finished yet, timeout makes this job very easy. One simple real world use case would be a lazy site-to-site synchronization using a rsync job run every night when the Internet uplink can be fully used and stop it right before people will need the network. Such a scenario can be done with timeout 8h rsync -a /data/ remote:/data/ and started from a cron job at 00h00. In this case rsync would run at midnight and timeout would stop it at 8h00 if the job is not finished.