Jan
Jan

Reputation: 3154

How to set Last-Modified date of HTTP head via shell script

I want to set the last modified date of a file on a remote HTTP server to a shell script variable.

CATEGORIES_DATE=$(date -d "$(curl -s -I -u ${URL} | grep Last-Modified | SOMETHING HERE)" +%Y-%m-%d)

The server is responding with: Last-Modified: Sat, 28 Jul 2012 09:15:30 GMT and I want to have CATEGORIES_DATE=2012-07-28 in the end.

Upvotes: 1

Views: 187

Answers (1)

user1461760
user1461760

Reputation:

You can use awk + date:

CATEGORIES_DATE="$(curl -s -I "${URL}" | awk '/^Last-Modified:/ { DATE=$3 " " $4 " " $5 ; system( "date -d \""  DATE "\" \"+%Y-%m-%d\"" ) }' )"

Awk will extract the required fields and feed them to date.

Upvotes: 1

Related Questions