Skip to content

Instantly share code, notes, and snippets.

@artyom
Created September 12, 2012 14:19
Show Gist options
  • Save artyom/3706910 to your computer and use it in GitHub Desktop.
Save artyom/3706910 to your computer and use it in GitHub Desktop.
Check if file is newer than X minutes
#!/bin/sh -eu
usage () { printf "%s file [time-in-minutes]\n" ${0##*/} >&2 ; }
test $# -eq 0 && { usage ; exit 2 ; }
WHAT=$1
test -e $WHAT || { echo "$WHAT not found" >&2 ; exit 2 ; }
MINUTES=${2:-30}
case ${0##*/} in
older*)
test $(($(date +%s)-$(stat --printf "%Y\n" "$WHAT"))) -gt $(($MINUTES*60))
;;
newer*)
test $(($(date +%s)-$(stat --printf "%Y\n" "$WHAT"))) -lt $(($MINUTES*60))
;;
*)
usage
exit 2
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment