Archive

Posts Tagged ‘ash’

Curling

November 29th, 2010 subogero Comments off

I’m not referring to the most boring sport EVER. Instead, it’s a command line tool I’ve discovered recently: curl. You specify a URL on the command line (e.g. curl http://napirajz.hu), and it prints the contents to standard output.

Time to write my most popular website ever:

The business case:
Bloody multinational corporations filter the internet. One cannot access inspiring content like http://napirajz.hu. Let’s make it accessible.

The tools:
My OpenWrt router hanging on the internet. I’ll create a mirror site on it, refreshed every day at 5:00 (before breakfast), 9:00 (arriving at the office), 13:00 (after lunch) and 18:00 (before I get home).

The beloved cron daemon will do the timing. And the mirroring? On OpenWrt, one lacks the luxuries or Perl and even the cosy comfort of Bash. One has to make do with the BusyBox versions of the Almquist Shell (ash), curl, sed and wget.

#!/bin/ash
PICS=`curl 'http://napirajz.hu' 2>/dev/null \
| sed -nr 's,^[\t ]*<p><img src=\"([a-z0-9/_.]+)\".+$,http://napirajz.hu\1,p'`
rm -f *.jp*
echo '<html><head><title>subogero napi</title></head><body>'
echo '<h1 align="center">subogero napi</h1>'
echo '<hr>'
for i in $PICS; do
 wget $i
 echo $i \
 | sed -r 's,^.+/([a-z0-9_]+)(\.[jpeg]+)$,<p><a href=\"napi/\1\2\">\1</a>,'
done
echo '<hr>'
echo '(c) CC - Mer&eacute;nyi D&aacute;niel'
echo '<br>Eredeti: h t t p : / / n a p i r a j z . h u'
echo '<p>Friss&iacute;tve:'
date "+%Y.%m.%d %H:%M"
echo '</body></html>'

See the result at http://subogero.dyndns.org/git/napi/

Categories: Uncategorized Tags: , , , , ,