Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get lastModified and convert to local TZ with RFC-3339 format

Get lastModified and convert to local TZ with RFC-3339 format

How to Use

  • put in /usr/local/bin/lastmod or /usr/bin/lastmod

$ lastmod http://example.com [http://example.com/foo http://example.com/bar ...]

lastmod

for inside of Cygwin

Based onliner

direct input to console, like this:

$ date --rfc-3339="seconds" -d "`wget -S --spider http://s.hatena.ne.jp/js/HatenaStar.js 2>&1 |\
> grep -o -P "Last-Modified:.*" --line-buffered |\
> sed -u -r "s/Last-Modified:\s//"`"
2012-05-22 12:13:51+09:00

Environment

$ uname -a
CYGWIN_NT-5.1 %CONPUTERNAME% 1.5.25(0.156/4/2) 2008-06-12 19:34 i686 Cygwin

$ wget --version
GNU Wget 1.11.4

$ curl --version
curl 7.16.3 (i686-pc-cygwin) libcurl/7.16.3 OpenSSL/0.9.8l zlib/1.2.3 libssh2/0.15-CVS

$ grep --version
GNU grep 2.5.3

$ date --version
date (GNU coreutils) 6.10

lastmod-legacy

for msysGit(MinGW), Cygwin or old Distribution

Based onliner

direct input to console, like this:

$ date "+%Y-%m-%d %T%z" -d "`curl -sI http://s.hatena.ne.jp/js/HatenaStar.js |\
> grep -e "Last-Modified: " |\
> sed -u -r "s/Last-Modified:\s//"`"
  2012-05-22 12:13:51+0900

Environment

$ uname -a
MINGW32_NT-5.1 %CONPUTERNAME% 1.0.12(0.46/3/2) 2011-07-20 17:52 i686 unknown

$ curl --version
curl 7.21.1 (i686-pc-mingw32) libcurl/7.21.1 OpenSSL/0.9.8r zlib/1.2.3

$ grep --version
grep (GNU grep) 2.4.2

$ date --version
date (GNU sh-utils) 2.0
#!/usr/bin/bash
# LastModified convert to local TZ with RFC-3339 format inside of Cygwin
# @author noromanba
# @license Public Domain https://creativecommons.org/licenses/publicdomain/
for url in $@
do
date --rfc-3339="seconds" -d "`wget -S --spider $url 2>&1 |\
grep -o -P "Last-Modified:.*" --line-buffered |\
sed -u -r "s/Last-Modified:\s//"`"
done
#!/usr/bin/bash
# LastModified convert to local TZ with RFC-3339 format inside of msysGit(MinGW), Cygwin or old Distribution
# @author noromanba
# @license Public Domain https://creativecommons.org/licenses/publicdomain/
for url in $@
do
date "+%Y-%m-%d %T%z" -d "`curl -sI $url |\
grep -e "Last-Modified: " |\
sed -u -r "s/Last-Modified:\s//"`"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment