A home of miscellaneous projects by Paul Philippov.


How to compate remote LastModified time with local file time in BusyBox date

For some reason my busybox date does not recognize timezone format. So I had to over-engineer it.

rem_headers=$(curl --silent --head https://remote.web/online/file.gz)
rem_lm=$($rem_headers | grep "Date:" | cut -d: -f2,3,4 | sed 's/\sGMT\s*$//' | sed 's/^\s*//')
rem_ts=$(TZ=GMT date --date "${rem_lm}" -D "%a, %d %b %Y %T" +"%s" 2>&1)
loc_ts=$(TZ=GMT date -r "/path/to/local/file" +"%s" 2>&1)
[ "$rem_ts" -le "$loc_ts" ] && echo "same or older" || echo "newer"