You are not logged in.

#1 2010-05-23 21:27:23

BoySka
Member
Registered: 2008-05-09
Posts: 25

Age of latest Arch News post in bash

I was a looking for a simple bash way to know the age of the latest post on Arch News.
I found that it is very easy to do it, and I post it on the forum because I think it could be useful for script.
(Indeed, I was writing this to do my own "pacup" script: check news, etckeeper, pacman -Su, etckeeper)

$(($((`date '+%s'`-`curl -s http://www.archlinux.org/feeds/news/|xml sel -t -v '//lastBuildDate'|xargs -0 date '+%s' -d`))/60/60/24))

yep, this is a single line smile
Of course this lacks of readability. The "long" version is this:

latest_post_date=$(curl -s http://www.archlinux.org/feeds/news/|xml sel -t -v '//lastBuildDate')
latest_post_date_sec=$(date '+%s' -d "$latest_post_date")
let diff=`date '+%s'`-$latest_post_date_sec
echo $((diff/60/60/24))

The only dependencies are curl and xmlstarlet, which unfortunately is only in aur.
It shouldn't be difficult to write a version that doesn't need it, I suppose.

EDIT: added curl dependency

Last edited by BoySka (2010-05-24 06:23:12)

Offline

#2 2010-05-23 22:02:54

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Age of latest Arch News post in bash

I think you also need curl.

Edit:

curl -s http://www.archlinux.org/news/ | grep 2010 | head -n1 | cut -c 9-18

Last edited by karol (2010-05-23 22:31:48)

Offline

#3 2010-05-24 06:22:27

BoySka
Member
Registered: 2008-05-09
Posts: 25

Re: Age of latest Arch News post in bash

karol wrote:

I think you also need curl.

ooops, you're right of course

Edit:

curl -s http://www.archlinux.org/news/ | grep 2010 | head -n1 | cut -c 9-18

Wow, this is good, but it's year-dependant. So here is my proposal again:

curl -s http://www.archlinux.org/news/ | grep '<td>' |head -n1 |cut -c 9-18

Offline

#4 2010-05-24 07:01:30

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 881
Website

Re: Age of latest Arch News post in bash

Hope you dont mind I patched it a little.

curl -s http://www.archlinux.org/news/ | grep '<td>'|head -2|perl -pe 'chomp;s;^\s+<td>(.+)</td>;$1: ;'|perl -pe 's/<a href.+">(.+)<.+/$1\n/'

2010-05-17: 2010.05 snapshots. Less is more.

And if you only want the date:

perl -eMLWP::Simple 'for(get('http://www.archlinux.org/news/')){if($_=~/<td>(.+)<\/td>/){$f=$1;}print"$f\n";}'

Last edited by dmz (2010-05-24 07:13:16)

Offline

#5 2010-05-24 09:07:06

ilembitov
Member
Registered: 2008-10-07
Posts: 124

Re: Age of latest Arch News post in bash

If I get it right, you want to check whether there are any related notices every time the users performs an update? Is date-based really universal?

I would suggest grepping the news for the names of the packages that are getting updated.

Offline

#6 2010-05-24 18:53:44

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: Age of latest Arch News post in bash

Why not use rsstail instead?

Offline

#7 2010-05-24 19:52:01

BoySka
Member
Registered: 2008-05-09
Posts: 25

Re: Age of latest Arch News post in bash

dmz wrote:

Hope you dont mind I patched it a little.

I posted it here for this reason wink

curl -s http://www.archlinux.org/news/ | grep '<td>'|head -2|perl -pe 'chomp;s;^\s+<td>(.+)</td>;$1: ;'|perl -pe 's/<a href.+">(.+)<.+/$1\n/'

This output is very cool, and it doesn't even depends on xmlstarlet. Definitely +1

And if you only want the date:

perl -eMLWP::Simple 'for(get('http://www.archlinux.org/news/')){if($_=~/<td>(.+)<\/td>/){$f=$1;}print"$f\n";}'

this, instead, does nothing on my box sad

Offline

#8 2010-05-24 20:01:35

BoySka
Member
Registered: 2008-05-09
Posts: 25

Re: Age of latest Arch News post in bash

ilembitov wrote:

If I get it right, you want to check whether there are any related notices every time the users performs an update? Is date-based really universal?

No, it's not universal. But on my box it is pretty useful, since I do updates fairly often. So, only recent news are relevants.
Of course, keeping an md5sum somewhere would be more correct.

I would suggest grepping the news for the names of the packages that are getting updated.

Even this method is good, and I'm going to implement it wink

Offline

Board footer

Powered by FluxBB