Created
October 18, 2023 18:12
-
-
Save mathew-fleisch/cc0f66c833ecf15f3192ef0f416b62c5 to your computer and use it in GitHub Desktop.
Bash timer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
convertsecs() { | |
((h=${1}/3600)) | |
((m=(${1}%3600)/60)) | |
((s=${1}%60)) | |
printf "%02d:%02d:%02d\n" $h $m $s | |
} | |
started=$(date +%s) | |
current=$started | |
# timeout: 10 seconds | |
timeout=$((started+10)) | |
while [ $current -lt $timeout ]; do | |
current=$(date +%s) | |
diff=$((timeout-current)) | |
echo "timeout[$(convertsecs $diff)]" | |
sleep 1 | |
done | |
echo "Timeout!" |
Author
mathew-fleisch
commented
Oct 18, 2023
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment