Skip to content

Instantly share code, notes, and snippets.

@Galadirith
Forked from PHLAK/ping-test.sh
Created February 2, 2022 23:11
Show Gist options
  • Save Galadirith/4ed60652792a48ed3d5c29cc00a0da15 to your computer and use it in GitHub Desktop.
Save Galadirith/4ed60652792a48ed3d5c29cc00a0da15 to your computer and use it in GitHub Desktop.
24 hour while loop in bash
#!/bin/bash
## Script start time
START=$(date +%s)
## Total run time
DURRATION=$((60 * 60 * 24))
## Total running time
UPTIME=$(($(date +%s) - $START))
while [[ $UPTIME < $DURRATION ]]; do
## Logic here...
echo -n "Time remaining: "
echo $(($DURRATION - $UPTIME))
## Sleep for a bit
sleep 2
## Update running time
UPTIME=$(($(date +%s) - $START))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment