Last active
February 26, 2026 14:34
-
-
Save artsi0m/51e644b9d4eff2340fef4abf0ba13656 to your computer and use it in GitHub Desktop.
Get last post from a static page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env sh | |
| set -e | |
| set -o errexit | |
| Url=$1 | |
| Sleep_Arg=$2 | |
| usage() { | |
| echo "Usage: ./last-post.sh [url] [check interval: default is 1 min]" | |
| echo "Dependencies: curl, mail, Last-Modified http header" | |
| } | |
| get_http_header_last_modified () { | |
| curl "$1" --output /dev/null --silent --dump-header - \ | |
| | grep Last-Modified | |
| } | |
| notify_mail() { | |
| [ "$1" != "$2" ] \ | |
| && printf 'Page on address %s updated' "$3" \ | |
| | mail -s 'Page updated' "$USER" | |
| } | |
| main () { | |
| Last_Modified_First="$(get_http_header_last_modified "$Url")"; | |
| sleep "$Sleep_Arg" | |
| Last_Modified_Second="$(get_http_header_last_modified "$Url")"; | |
| notify_mail "$Last_Modified_First" "$Last_Modified_Second" "$Url" | |
| } | |
| [ -z "$Sleep_Arg" ] && Sleep_Arg=60 | |
| while true; | |
| do | |
| if [ -z "$Url" ]; then | |
| usage; exit 0; | |
| else main; | |
| fi | |
| done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment