How do i run something inside a bash script for a number of seconds?
-
Also see: How do i obtain the number of seconds my shell has been running?
May you want to run a certain tasks inside a script for a predefined amount of time, one way is:
#!/bin/bash run_time=$((SECONDS+10)) while [ $SECONDS -lt $run_time ] do uptime sleep 2 done
The result is run uptime every two seconds for no more than 10 seconds.
© Lightnetics 2024