Skip to content

Instantly share code, notes, and snippets.

@webcultist
Forked from PHLAK/ping-test.sh
Created April 5, 2020 17:43
Show Gist options
  • Save webcultist/92ad66a1ce1aaa51214d2200ba00b397 to your computer and use it in GitHub Desktop.
Save webcultist/92ad66a1ce1aaa51214d2200ba00b397 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