GPN8:Code: Unterschied zwischen den Versionen

aus dem Wiki des Entropia e.V., CCC Karlsruhe
(+Code-Kommentare)
Keine Bearbeitungszusammenfassung
Zeile 20: Zeile 20:
  <nowiki> cat "$@" | grep -Exv '\#!.*|[[:space:]]*' | wc</nowiki>
  <nowiki> cat "$@" | grep -Exv '\#!.*|[[:space:]]*' | wc</nowiki>
  ) | rs -t 3 3 | rs -e)
  ) | rs -t 3 3 | rs -e)
== [[Benutzer:Nomeata]] ==
Für L-seed gabs dieses „Alle Twit zu einem Thema suchen und eines nach dem anderen eine Minute lang in eine Datei schreib“-Skript. Braucht libwww-perl, libxml-xpath-perl und lynx.
<pre>
while sleep 60;
do
GET "http://search.twitter.com/search.atom?q=%23GPN8&since_id=$(cat msg.id)" > msg.atom
if xpath -q -e "//entry" msg.atom |grep -q .
then
xpath -q -e "//entry[last()]/id/text()" msg.atom |cut -d: -f3 > msg.id
echo -n \
$(echo $(
xpath -q -e '//entry[last()]/author/name/text()' msg.atom  |
lynx -dump -stdin|lynx -dump -stdin -nolist |
cut -d\( -f1
))"@twitter:" \
$(
xpath -q -e '//entry[last()]/content/text()' msg.atom  |
lynx -dump -stdin|lynx -dump -stdin -nolist
) \
> msg.txt
else
echo -n > msg.txt
fi
done
</pre>

Version vom 29. Juni 2009, 10:38 Uhr

Code und Basteleien

Auf dieser Seite kann sich jeder verewigen, der auf der GPN etwas programmiert oder gebaut hat.

user:kamikaze

Objektorientierte Shell-Skripte

Ich habe ein kleines Framework für objektorientierte Shell-Skripte geschrieben. Das wird irgendwann in http://bsdadminscripts.sf.net/ genutzt.

Den Code habe ich mal vorläufig auf BSDForen.de veröffentlicht: http://www.bsdforen.de/showthread.php?t=23245

Code-Kommentare

Im Rahmen einer kleinen Unterhaltung über Code-Kommentare, habe ich dieses kleine Skript hier produziert, das ausspuckt wir groß der Kommentaranteil in einem Shell-Skript ist. Das ganze funktioniert unter FreeBSD RELENG_7. Kann sein, das man mit GNU ein paar Parameter anpassen muss.

#!/bin/sh -f

apply -3 "sh -c 'echo %1: \$((%2 \* 100000 / %3 / 1000)).\$((%2 \* 100000 / %3 % 1000)) %'" $( (
	echo lines words bytes
	cat "$@" | grep -Exv '#\!.*|[[:space:]]*' | grep -E '^[[:space:]]*#' | wc
	cat "$@" | grep -Exv '\#!.*|[[:space:]]*' | wc
) | rs -t 3 3 | rs -e)

Benutzer:Nomeata

Für L-seed gabs dieses „Alle Twit zu einem Thema suchen und eines nach dem anderen eine Minute lang in eine Datei schreib“-Skript. Braucht libwww-perl, libxml-xpath-perl und lynx.

while sleep 60;
do
GET "http://search.twitter.com/search.atom?q=%23GPN8&since_id=$(cat msg.id)" > msg.atom 
if xpath -q -e "//entry" msg.atom |grep -q .
then
	xpath -q -e "//entry[last()]/id/text()" msg.atom |cut -d: -f3 > msg.id
	echo -n \
	$(echo $(
		xpath -q -e '//entry[last()]/author/name/text()' msg.atom  |
		lynx -dump -stdin|lynx -dump -stdin -nolist |
		cut -d\( -f1
	))"@twitter:" \
	$(
		xpath -q -e '//entry[last()]/content/text()' msg.atom  |
		lynx -dump -stdin|lynx -dump -stdin -nolist
	) \
	 > msg.txt
else
	echo -n > msg.txt
fi
done