I have a bash script with a function named speedtest created like this:
function speedtest { echo $time_min; echo $(date +%R),"$(speedtest-cli --csv)" >>temp.csv # Outputs van datum en speedtest in temp.csv cut -d, -f1,8 < temp.csv >> output2.csv; # Verwijderd onnodige info uit temp en plaatst het in output.csv awk -F , -v OFS=, '$3/=1000000' <output2 >output2.csv # Zet bits/s om naar Mbp/s rm temp.csv; }I would like to run this function exactly x minutes. Note that the function takes some time to run. If I run it every x minutes, that's not the same thing as running it, sleeping for x minutes and then running it again. I want to start the function exactly every x minutes.
41 Answer
It seems you're not allowed to use cron.
In that case, you could use an infinite loop calls this function in the background and then sleeps for x minutes:
while true; do speedtest & sleep 60; doneJust make sure to sleep long enough so that the current speedtest call terminates before the sleep is over, to avoid multiple instances of the process running in parallel.
If you don't want to keep a terminal open with this running,
you can do this in a screen or tmux session.