Skip to content

Instantly share code, notes, and snippets.

@PHLAK
Created February 11, 2014 18:11
Show Gist options
  • Save PHLAK/8940598 to your computer and use it in GitHub Desktop.
Save PHLAK/8940598 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