Skip to content

Instantly share code, notes, and snippets.

@jpukg
Forked from PHLAK/ping-test.sh
Created June 18, 2018 11:52
Show Gist options
  • Save jpukg/c141417d8996cdf6b07a281e7ae601a2 to your computer and use it in GitHub Desktop.
Save jpukg/c141417d8996cdf6b07a281e7ae601a2 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