<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7573311539006121754</id><updated>2011-11-27T16:54:25.533-08:00</updated><category term='xml'/><category term='make'/><category term='media'/><category term='awk'/><category term='find'/><category term='init'/><category term='emacs'/><category term='stat'/><category term='shell'/><category term='python'/><category term='gentoo'/><category term='latex'/><category term='graph theory'/><category term='openvpn'/><category term='network'/><category term='vim'/><category term='postscript'/><category term='bash'/><category term='lirc'/><category term='sed'/><title type='text'>automatenkaffee</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>35</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-4265685361305402777</id><published>2010-12-04T08:35:00.000-08:00</published><updated>2010-12-04T08:39:31.425-08:00</updated><title type='text'>bash completion for unison</title><content type='html'>just add the following to you &lt;code&gt;~/.bashrc&lt;/code&gt; or to &lt;code&gt;/etc/bash_completion.d/unison&lt;/code&gt;:
&lt;pre class="prettyprint lang-bash"&gt;
_unison() { COMPREPLY=( $(compgen -W "$(find ~/.unison -name '*.prf' -printf '%P ')" -- "${COMP_WORDS[COMP_CWORD]}" ) ); }
complete -F _unison unison
&lt;/pre&gt;

&lt;a href="http://www.cis.upenn.edu/~bcpierce/unison/"&gt;
http://www.cis.upenn.edu/~bcpierce/unison/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-4265685361305402777?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/4265685361305402777/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/12/bash-completion-for-unison.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/4265685361305402777'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/4265685361305402777'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/12/bash-completion-for-unison.html' title='bash completion for unison'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-3116534947922657447</id><published>2010-07-10T08:51:00.000-07:00</published><updated>2010-07-10T09:33:01.678-07:00</updated><title type='text'>C# Conditional Execution</title><content type='html'>[ConditionalAttribute("DEBUG")]
for methods. All calls to that method are only executed in Debug builds!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-3116534947922657447?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/3116534947922657447/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/07/c-conditional-execution.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/3116534947922657447'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/3116534947922657447'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/07/c-conditional-execution.html' title='C# Conditional Execution'/><author><name>sothim</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='21' src='http://static.flickr.com/56/167344348_dfb7391112_m.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-9192440309728931514</id><published>2010-06-01T15:30:00.000-07:00</published><updated>2010-06-09T06:43:49.701-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><title type='text'>man wrapper: man in own window</title><content type='html'>&lt;p&gt;Alt-F2, man emacs.&lt;/p&gt;

&lt;p&gt;well, this does not work. not automatically.&lt;p&gt;
&lt;p&gt;i created a wrapper-script in ~/bin (which is first in my path variable) with the following content:&lt;/p&gt;

&lt;p&gt;&lt;pre class="prettyprint lang-bash"&gt;
#!/bin/bash
# mru, jun 2010

# if ! [ -t 0 ]; then
if [ "$DISPLAY" ]; then
 exec gnome-terminal --hide-menubar --title "man $@" -x /usr/bin/man "$@"
else 
 exec /usr/bin/man "$@"
fi
&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;to make it work.&lt;/p&gt;

&lt;p&gt;one could use
&lt;kbd class="prettyprint lang-bash"&gt;if ! [ -t 0 ]; then&lt;/kbd&gt;
to get a normal in-terminal man if in terminal and a seperate gnome-terminal if in X11.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-9192440309728931514?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/9192440309728931514/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/06/man-wrapper-man-in-own-window.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/9192440309728931514'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/9192440309728931514'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/06/man-wrapper-man-in-own-window.html' title='man wrapper: man in own window'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-8070966662961221147</id><published>2010-05-27T16:17:00.000-07:00</published><updated>2010-06-22T14:27:54.944-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='latex'/><title type='text'>latexmk super powers</title><content type='html'>&lt;p&gt;&lt;code&gt;latexmk&lt;/code&gt; is a handy tool to build latex documents. these days i investigated in the advanced usage of &lt;code&gt;latexmk&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;latexmk&lt;/code&gt; can use configuration files, &lt;code&gt;latexmkrc&lt;/code&gt; in the current directory is used as a default, then &lt;code&gt;~/.latexmkrc&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;with 
&lt;kbd&gt;
latexmk -pvc
&lt;/kbd&gt;
 latexmk watches a .tex file and builds it whenever its content or a dependency of it changes. &lt;kbd&gt;-pvc&lt;/kbd&gt; also opens a viewer for the file and updates it, so it really supports the workflow when editing latex documents.&lt;/p&gt;

&lt;p&gt;a sample &lt;code&gt;latexmkrc&lt;/code&gt; file might look like that:
&lt;pre class="prettyprint lang-perl"&gt;
$pdf_previewer = 'start evince';
@default_files = ('thesis');
$print_type = 'pdf';
$pdf_mode = 1;
$pdflatex = 'pdflatex -interaction=nonstopmode -halt-on-error';
&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;update: &lt;kbd&gt;$pdflatex = 'pdflatex -interaction=nonstopmode -halt-on-error';&lt;/kbd&gt; makes &lt;code&gt;pdflatex&lt;/code&gt; stop on the first error, not asking for any user input.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-8070966662961221147?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/8070966662961221147/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/05/latexmk-super-powers.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/8070966662961221147'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/8070966662961221147'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/05/latexmk-super-powers.html' title='latexmk super powers'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-6642440692815708901</id><published>2010-05-27T16:15:00.001-07:00</published><updated>2010-06-01T15:59:46.376-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><title type='text'>watch-files</title><content type='html'>&lt;p&gt;just like continuous-make, but executes arbitrary commands when a file changes.&lt;/p&gt;


&lt;p&gt;&lt;pre class="prettyprint lang-bash"&gt;
#! /bin/bash

# mru, feb 2010
# if a file changes, execute command

# example:
#
# watch-file document.tex lit.bib latexmk

# 

function error() {
 echo "error: $@"
 echo "${0##*/} {files-to-watch} 'command-upon-modification'"
 exit 1
}

if [ ${#} -lt 2 ]; then
 error "not enough arguments"
fi


while [ $# -gt 1 ]; do
 FILES=(${FILES[*]} "$1")
 shift
done

CMD=$*

for i in "${FILES[@]}"; do
 if [ -z "$i" ] || ! [ -f "$i" ]; then
  error "no such file: $i"
 fi
done

echo "${0##*/}: onchange ("
for i in "${FILES[@]}"; do
 echo " * $i"
done
echo ") { ${CMD} }"

ftime() { stat -c %y "${FILES[@]}"; }

D=$(ftime)
while true; do
 sleep 1
 DN=$(ftime)
 if [ "$D" != "$DN" ]; then
  $CMD
  D="$DN"
 fi
done
&lt;/pre&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-6642440692815708901?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/6642440692815708901/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/05/watch-files.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/6642440692815708901'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/6642440692815708901'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/05/watch-files.html' title='watch-files'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-9025447313408066356</id><published>2010-05-27T16:08:00.000-07:00</published><updated>2010-06-01T15:50:13.363-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><category scheme='http://www.blogger.com/atom/ns#' term='make'/><title type='text'>continuous make</title><content type='html'>&lt;p&gt;build-on-save is easy. i put this in my &lt;code&gt;.bash_aliases&lt;/code&gt; and use it everywhere!&lt;/p&gt;

&lt;p&gt;&lt;pre class="prettyprint lang-bash"&gt;
continuous-make() {
 while true; do
  if ! make "$@" -q; then
   make "$@"
  fi
  sleep 1
 done
}
&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;you can use it like that:&lt;/p&gt;
&lt;kbd&gt;continuous-make doc&lt;/kbd&gt;
&lt;p&gt; and it will call &lt;code&gt;make doc&lt;/code&gt; whenever a dependency of &lt;code&gt;doc&lt;/code&gt; is changed.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-9025447313408066356?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/9025447313408066356/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/05/continous-make.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/9025447313408066356'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/9025447313408066356'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/05/continous-make.html' title='continuous make'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-6426846760685280717</id><published>2010-05-27T16:03:00.001-07:00</published><updated>2010-05-28T07:55:30.888-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><category scheme='http://www.blogger.com/atom/ns#' term='find'/><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><title type='text'>mydoc: documentation management</title><content type='html'>&lt;p&gt;i have a lot of pdf files lying around. some of these files are datasheets, some manuals. i repeatedly access them, and because usually i can't find them fast enough, i search the internet and download it the thousandth time. but not any longer! &lt;code&gt;mydoc&lt;/code&gt; behaves like &lt;code&gt;texdoc&lt;/code&gt;, but for my own documents.&lt;/p&gt;

&lt;p&gt;it accepts arguments that are used as conjuncted filters.&lt;/p&gt;
&lt;p&gt;if more files match the filters, a selection dialog is displayed&lt;/p&gt;
&lt;p&gt;it detects if its called from console or from gui (Alt-F2, e.g.).&lt;/p&gt;

&lt;p&gt;&lt;pre class="prettyprint lang-bash"&gt;
#! /bin/bash

# search $MYDOCPATH for pdf documents
# commandline arguments are used as conjucted -iname's
#
# mru, may 2010


# configure where to search for the pdf's
MYDOCPATH=~/dev/01atmel/terrarium/docs/:~/dev/01atmel/stepper/docs/:~/books/




set -f  # no globbing, free the star!


# detect if run in console
# the variable TERM is used to automagically call the right function
if [ -t 0 ]; then
 TERM='cli'
else
 TERM='x11'
fi

error_cli() { echo "$*"; }
error_x11() { zenity --warning --text "$*" --title "${0##*/}"; }
info_cli()  { echo "$*"; }
info_x11()  { zenity --info --text "$*"  --title "${0##*/}"; }

usage()     { info_$TERM "usage: ${0##*/} {filter-string}"; } 
open()      { gnome-open "$@"; }

get_choice_cli() {
 PS3=$'more possible matches; select the file to open or change filter: '
 select c in $@ ; do  
  echo $c
  break
 done
}

get_choice_x11() {
 zenity --list \
  --width=800 \
  --height=450 \
  --text "select file" \
  --title "${0##*/}: filter not unique" \
  --column "filename" \
  "$@"
}

if [ -z "$MYDOCPATH" ]; then
 error_$TERM "\$MYDOCPATH not set"
 exit 1
fi


# create the `find` query, search for --help
while (( $# &gt; 0 )); do
 if [ "$1" = "--help" ]; then
  usage
  exit 1
 fi

 QUERY="$QUERY -iwholename *$1*"
 shift
done


# call `find` for all paths in $MYDOCPATH and store the result in
# RESULTS

RESULTS=$(IFS=$': '; for i in $MYDOCPATH; do
 find $i -iname "*pdf" $QUERY
done)

# well, nothing found, RESULTS is empty
if [ -z "$RESULTS" ]; then
 info_$TERM "nothing found; stopping"
 exit 1
fi

# on unique match, open pdf
if (( $(wc -l &lt;&lt;&lt; "$RESULTS") == 1 )); then
 open "$RESULTS"

# multiple matches, open selection
else
 IFS=$'\n'
 c=$(get_choice_$TERM $RESULTS)
 [ "$c" ] &amp;&amp; open "$c"
fi
&lt;/pre&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-6426846760685280717?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/6426846760685280717/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/05/documentation-management.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/6426846760685280717'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/6426846760685280717'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/05/documentation-management.html' title='mydoc: documentation management'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-7443600444830228252</id><published>2010-05-27T15:54:00.000-07:00</published><updated>2010-05-27T16:28:53.534-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='latex'/><category scheme='http://www.blogger.com/atom/ns#' term='sed'/><title type='text'>prettyprint bibtex .bib files</title><content type='html'>&lt;p&gt;some sed code to &lt;em&gt;optimize&lt;/em&gt; .bib code&lt;/p&gt;

&lt;p&gt;invoke like this:
&lt;kbd&gt;sed -f pretty-bib.sed literature.bib&lt;/kbd&gt;
&lt;/p&gt;

&lt;p&gt;&lt;pre class="prettyprint"&gt;
# pretty-printer for .bib files
# mru, may 2010


# canonical comments
s/^%[ \t]*/% /

# canoical spaces around assignments
s/^[^%][ \t]*\([a-zA-Z0-9]\+\)[ \t]*=[ \t]*/  \1 = /

# double-braces for title and notes
s/title = \({[^{].*}\)/title = {\1}/
s/note = \({[^{].*}\)/note = {\1}/

# remove trailing whitespace
s/[ \t]*$//;

# delete multiple empty lines
/./,/^$/!d
&lt;/pre&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-7443600444830228252?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/7443600444830228252/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/05/prettyprint-bibtex-bib-files.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/7443600444830228252'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/7443600444830228252'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/05/prettyprint-bibtex-bib-files.html' title='prettyprint bibtex .bib files'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-6103180872006744034</id><published>2010-02-21T12:05:00.000-08:00</published><updated>2010-02-22T02:32:32.151-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='stat'/><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><title type='text'>file modification time</title><content type='html'>&lt;p&gt;To get the access|modification|change time of a file, one could use &lt;code&gt;stat&lt;/code&gt; to get the data. For example:

&lt;p&gt;&lt;kbd class="prettyprint" title="stdin"&gt;
$ stat -c %y ~/.bash_aliases
&lt;/kbd&gt;
&lt;kbd&gt;
2010-02-20 17:12:31.161203715 +0100
&lt;/kbd&gt;

&lt;p&gt;Of course, this can be easily &lt;code&gt;cut&lt;/code&gt;ted to get only the date:

&lt;p&gt;&lt;kbd class="prettyprint" title="stdin"&gt;
$ stat -c %y ~/.bash_aliases | cut -d' ' -f1
&lt;/kbd&gt;
&lt;kbd&gt;
2010-02-20
&lt;/kbd&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-6103180872006744034?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/6103180872006744034/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/file-modification-time.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/6103180872006744034'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/6103180872006744034'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/file-modification-time.html' title='file modification time'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-9205986311637803681</id><published>2010-02-20T15:41:00.000-08:00</published><updated>2010-02-21T17:36:24.817-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='make'/><title type='text'>make arch ftw!</title><content type='html'>&lt;p&gt;I really like using &lt;code&gt;Makefile&lt;/code&gt;s to package my projects into &lt;code&gt;.tar.gz&lt;/code&gt; files. And I really like those &lt;code&gt;.tar.gz&lt;/code&gt; where all the content is contained in a single top-level directory, named exactly as the archive file, so it's easy to delete all files easily when extracted so a crowded directory.

&lt;p&gt;This can be easily achieved using something like this:


&lt;p&gt;&lt;pre class="prettyprint lang-make" title="Makefile"&gt;
TITLE = music-quality-$(shell date +%Y%m%d)

arch:
 tar cvzf $(TITLE).tar.gz \
  --transform 's#^#$(TITLE)/#' \
  --exclude '*~' \
  --exclude plot* \
  --exclude feature_pres \
  src/*.m

.PHONY: arch
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-9205986311637803681?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/9205986311637803681/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/make-arch-ftw.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/9205986311637803681'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/9205986311637803681'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/make-arch-ftw.html' title='make arch ftw!'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-5005429497141737968</id><published>2010-02-19T09:28:00.000-08:00</published><updated>2010-05-27T17:08:56.067-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='sed'/><category scheme='http://www.blogger.com/atom/ns#' term='postscript'/><title type='text'>multiline sed</title><content type='html'>&lt;p&gt;Given you have a PostScript file that contains blocks like the following, but with different commands repeatedly:

&lt;p&gt;&lt;pre class="prettyprint" title="tmp.ps"&gt;
gsave
/Courier findfont 10 scalefont ISOEncode setfont
0.000 0.000 0.000 setrgbcolor AdjustColor
202 2.8421709430404e-14 [
[(0.4)]
] 12 -0.5 1 0 false DrawText
&lt;/pre&gt;

or

&lt;p&gt;&lt;pre class="prettyprint" title="tmp.ps"&gt;
gsave
/Helvetica findfont 10 scalefont ISOEncode setfont
0.000 0.000 0.000 setrgbcolor AdjustColor
10 240 [
[(File: file1.wav   Page: 1 of 3   Printed: Fri Feb 19 18:32:26)]
] 14 -0 0 0 false DrawText
grestore
&lt;/pre&gt;

&lt;p&gt;and you want to remove those blocks that match '&lt;code&gt;(File&lt;/code&gt;' in the fifth line of input, you could try this:

&lt;kbd class="prettyprint" title="stdin"&gt;
sed -e '/gsave/ { N; N; N; N; /(File/ { N; N; d; } }'
&lt;/kbd&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-5005429497141737968?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/5005429497141737968/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/multiline-sed.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/5005429497141737968'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/5005429497141737968'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/multiline-sed.html' title='multiline sed'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-1434791215485517508</id><published>2010-02-19T09:25:00.000-08:00</published><updated>2010-02-21T17:38:06.710-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><category scheme='http://www.blogger.com/atom/ns#' term='find'/><title type='text'>server backup script</title><content type='html'>&lt;p&gt;My Server creates daily backups incremental backups to monthly full backups. It will keep the last three daily backups, as well as the last three monthly backups.


&lt;p&gt;&lt;pre class="prettyprint" title="backup.sh"&gt;
#!/bin/bash

# mru, feb 2010

# make backups.
#


DATE_D=$(date "+%Y%m%d")
DATE_M=$(date "+%Y%m")

BACKUPS=/var/backups
TARGET_D=${BACKUPS}/daily_backup_${DATE_D}.tar.gz
TARGET_M=${BACKUPS}/monthly_backup_${DATE_M}.tar.gz
RECEIVER=mru
TAROPTS=" --preserve-permission --label=$DATE_D"

FILES='
root
home
etc
boot
var/trac
var/www
var/mail
var/repositories
'

EXCLUDE_CLAUSE="
--exclude *~
--exclude ${BACKUPS}
--exclude root/.cpan
--exclude root/caldav
--exclude root/tmp
"

trap '{
 echo \"Failed. Stopping.\";
 exit 1;
 if [ -f "$TARGET" ]; then
   rm $TARGET;
 fi
}' ERR

# remove old files

OLD_D=$(find $BACKUPS -name daily_backup_????????.tar.gz | sort -n | head -n -3)
OLD_M=$(find $BACKUPS -name monthly_backup_??????.tar.gz | sort -n | head -n -3)
OLD=${OLD_M}${OLD_D}
echo "$OLD" | xargs --no-run-if-empty rm

# make monthly spinoff

if [ -f $TARGET_M ]; then
    TAROPTS+=" --newer $TARGET_M"
    TARGET=$TARGET_D
else
    TARGET=$TARGET_M
fi


# create archive
# chdir to / to get the right globbing
( cd / &amp;&amp; tar czf "$TARGET" $TAROPTS $EXCLUDE_CLAUSE $FILES )


chmod og-r "$TARGET"

# send report

mail -s "Backup Message for ${HOSTNAME} $(date)" ${RECEIVER} &amp;lt;&amp;lt;EOF
Backup created.

Filename: $TARGET
size:     $(ls -lah $TARGET)

$(if [ -n "$OLD" ]; then echo "==== removed these files: $OLD"; fi)

==== archive content $TARGET:
$(tar tzf $TARGET)

==== folder content $BACKUPS:
$(find ${BACKUPS})
EOF

&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-1434791215485517508?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/1434791215485517508/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/server-backup-script.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/1434791215485517508'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/1434791215485517508'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/server-backup-script.html' title='server backup script'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-5154302562707236295</id><published>2010-02-19T09:21:00.000-08:00</published><updated>2010-02-22T11:14:17.007-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>server status email</title><content type='html'>&lt;p&gt;My server sends me an email about it's status every day:

&lt;p&gt;&lt;pre class="prettyprint lang-bash" title="statusmail.sh"&gt;
&lt;![CDATA[#!/bin/bash

RECEIVER=mru

function run() {
    echo 
    echo "$@:"
    $@
}


mail -s "Status Message for ${HOSTNAME} $(date)" ${RECEIVER} &lt;&lt;EOF

Server Status

$(run date)
$(run uptime)
$(run df -h)
$(run w)
$(run netstat -utpa)
$(run tail /var/log/messages)
$(run tail /var/log/auth.log)
$(run tail /var/log/apache2/error.log)
EOF
]]&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-5154302562707236295?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/5154302562707236295/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/server-status-email.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/5154302562707236295'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/5154302562707236295'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/server-status-email.html' title='server status email'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-8359504597949925053</id><published>2010-02-09T07:22:00.000-08:00</published><updated>2010-02-09T07:35:18.045-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='network'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><title type='text'>Key Fingerprint to Wikimedia Commons Image</title><content type='html'>It's been some time, since my last serious python code, so excuse the mess ;) This will take any key fingerprint, for e.g. from ssh, in a hexadicaml format and show an image from commons.wikimedia.org which represents the key. The script will hash the key and does some sort of table lookup. I still need to implement some double hashing, when the matching image has a too high time offset, to eliminate some collisions. The current implementation also can't really deal with deleted images, tho I came up with some workarounds to that already.

&lt;p&gt;&lt;pre class="prettyprint lang-python"&gt;
#!/usr/bin/python

# convert ssh key figerprint to wikimedia commons image

import os
import sys
import commands

from datetime import datetime
from datetime import timedelta

import re

from xml.sax import saxutils
from xml.sax import make_parser
from xml.sax.handler import feature_namespaces


def convertMonth(ds):
    """ Replaces all written out months in a string with a xx number."""
    # don't depend on locals
    ds = ds.replace("January", "01") 
    ds = ds.replace("February", "02") 
    ds = ds.replace("March", "03") 
    ds = ds.replace("April", "04") 
    ds = ds.replace("May", "05") 
    ds = ds.replace("June", "06") 
    ds = ds.replace("July", "07") 
    ds = ds.replace("August", "08") 
    ds = ds.replace("September", "09") 
    ds = ds.replace("October", "10") 
    ds = ds.replace("November", "11") 
    ds = ds.replace("December", "12") 
    return ds



class ImageParser(saxutils.DefaultHandler):

    def __init__(self):
       self.inThumb = False
       self.dateElement = False
       self.thumbs = []

    def startElement(self, name, attrs):

        if self.dateElement:
            self.dateElement = False

        if name == 'div':
            if attrs.get('class', None) == 'thumb':
                self.inThumb = True

        if self.inThumb:
            if name == 'img':
                self.thumbs.append([attrs.get('src', None)])
            if name == 'i':
                self.dateElement = True 
                self.inThumb = False

    def characters(self, content):
        if self.dateElement:
            date = datetime.strptime(convertMonth(content), "%H:%M, %d %m %Y")
            self.thumbs[len(self.thumbs)-1].append(date)

    def endDocument(self):
        self.thumbList = []
        for l in self.thumbs:
            if l[0].find('http') != -1:
                if len(l) == 2:
                    self.thumbList.append(l)


class HashFunction:

    def __init__(self, startDate, duration, ticSize):
        """ Provides a Hash function, which takes any integer
        and returns a date within a given interval.

        Keyword Arguments:
        startDate -- the maximum date in the time interval, a datetime object
        duration  -- the positiv length of the timer interval, a deltatime object
        ticSize   -- the tic size in seconds is the unit in which the interval is divided
        """
        self.startDate = startDate
        self.duration = duration
        self.ticSize = ticSize

        seconds = duration.days*24*60*60 + duration.seconds
        self.numHashes = seconds / ticSize

    def h(self, x):
        """ Converts an Integer to a date in the configured period,
        based on a hashfunction.
        """
        h1 = x%self.numHashes
        second = h1 * self.ticSize
        return self.startDate - timedelta(0, second)
        
    def hFormat(self, x):
        """ Converts an Integer to a date in the configured period,
        based on a hashfunction. The date is formated string.
        """
        dt = self.h(x)
        return dt.strftime("%Y%m%d%H%M%S")

        
class KeyImage:

    def __init__(self):
        self.hf = HashFunction(startDate, duration, resolution)

    def __init__(self, startDate=datetime(2010, 2, 1, 12, 00, 00), duration=timedelta(days=365*4), resolution=60):
        self.hf = HashFunction(startDate, duration, resolution)

    def getImage(self, x, size=-1):
        """ Converts an Integer value to an image url from wikimedia commons."""
        # hasing 
        imageDate = self.hf.hFormat(x)

        # download html file
        url = "'http://commons.wikimedia.org/w/index.php?title=Special:NewFiles&amp;from=" + imageDate + "'"
        htmlFilename = "/tmp/commons_thumbs.html"
        commands.getstatusoutput("wget -E " + url + " -O " + htmlFilename)

        # parse xml file
        parser = make_parser()                  
        ip = ImageParser()
        parser.setFeature(feature_namespaces, 0)
        parser.setContentHandler(ip)
        file = open(htmlFilename)
        parser.parse(file)

        # remove temporary html file
        commands.getstatusoutput("rm " + htmlFilename)

        imageUrl = ip.thumbList[0][0]
        if (size &gt; -1):
            imageUrl = re.sub("[0-9]{2,3}px", str(size) + "px", imageUrl)

        return imageUrl
        

def main():
    skey = sys.argv[1].replace(".","").replace(":","")
    try:
        key = int(skey, 16)
    except:
        sys.stderr.write("[ERROR] Invalid Key")
        sys.exit(1)

    thumbSize = -1
    if len(sys.argv) &gt;= 3:
        try:
            thumbSize = int(sys.argv[2])
        except:
            sys.stderr.write("[ERROR] Invalid Size")
            sys.exit(1)

    ki = KeyImage()
    print ki.getImage(key, thumbSize)

main()
&lt;/pre&gt;

Here is a short wrapper script, which downloads the image and displays it with feh.

&lt;p&gt;&lt;pre class="prettyprint lang-bash"&gt;
#!/bin/bash

IMAGEURL=`key_to_thumb.py $1 $2|tail -1`
echo $IMAGEURL
TMPFILE="/tmp/kthumb.img"
wget "$IMAGEURL" -O$TMPFILE &amp;&gt; /dev/null
feh $TMPFILE
rm $TMPFILE
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-8359504597949925053?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/8359504597949925053/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/key-fingerprint-to-wikimedia-commons.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/8359504597949925053'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/8359504597949925053'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/key-fingerprint-to-wikimedia-commons.html' title='Key Fingerprint to Wikimedia Commons Image'/><author><name>DD</name><uri>http://www.blogger.com/profile/09516860909544238970</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-7396685339420737363</id><published>2010-02-06T16:17:00.000-08:00</published><updated>2010-02-06T16:25:55.610-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='network'/><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>Tor Network Status</title><content type='html'>This will pull a csv file with data from all Tor nodes running in the network and print basic bandwith statistics. I wrote this script to estimate, if adding more non-exit nodes to the tor network could speed it up, or if the exit nodes bandwith is the bottle neck anyway.

&lt;p&gt;&lt;pre class="prettyprint lang-bash"&gt;
#!/bin/bash

wget http://torstatus.kgprog.com/query_export.php/Tor_query_EXPORT.csv -P/tmp &amp;&gt; /dev/null

BANDWITH=`cat /tmp/Tor_query_EXPORT.csv |sed 1d|cut -d, -f3`
EXIT=`cat /tmp/Tor_query_EXPORT.csv |sed 1d|cut -d, -f10`
rm /tmp/Tor_query_EXPORT.csv

NUMNODES=0
NUMEXITS=0

BEXIT=0
BNOEXIT=0
BTOTAL=0

while read -u3 bandw; read -u4 exit 
do 
    BTOTAL=$(($BTOTAL+$bandw))
    NUMNODES=$(($NUMNODES+1))

    if [ $exit = '1' ]
    then
        BEXIT=$(($BEXIT+$bandw)) 
        NUMEXITS=$(($NUMEXITS+1))
    else
        BNOEXIT=$(($BNOEXIT+$bandw)) 
    fi
done 3&lt;&lt;&lt;"$BANDWITH" 4&lt;&lt;&lt;"$EXIT"

echo "Active Tor Routers:" $NUMNODES
echo "Exit Nodes" $NUMEXITS "("$(($(($NUMEXITS*100))/$NUMNODES))"%)"
echo "Bandwith Exits: " $BEXIT "kB/s" "("$(($BEXIT/1024))" MB/s)"
echo "Bandwith rest:  " $BNOEXIT "kB/s" "("$(($BNOEXIT/1024))" MB/s)"
echo "Bandwith total: " $BTOTAL   "kB/s" "("$(($BTOTAL/1024))" MB/s)"
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-7396685339420737363?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/7396685339420737363/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/tor-network-status.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/7396685339420737363'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/7396685339420737363'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/tor-network-status.html' title='Tor Network Status'/><author><name>DD</name><uri>http://www.blogger.com/profile/09516860909544238970</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-173498278986028431</id><published>2010-02-06T12:00:00.001-08:00</published><updated>2010-02-07T03:16:03.679-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='gentoo'/><category scheme='http://www.blogger.com/atom/ns#' term='network'/><category scheme='http://www.blogger.com/atom/ns#' term='init'/><category scheme='http://www.blogger.com/atom/ns#' term='openvpn'/><title type='text'>Multiple VPN Tunnels, Gentoo Style</title><content type='html'>Let &lt;em&gt;tunname&lt;/em&gt; be the specific VPN tunnel to be started, using &lt;em&gt;/etc/openvpn/tunname.conf&lt;/em&gt; as the config file. Then the required initscripts are created and started as follows:
&lt;pre class="code" class="bash"&gt;
# creating 
ln -s /etc/init.d/openvpn /etc/init.d/tunname

# starting 
/etc/init.d/tunname start
&lt;/pre&gt;
&lt;p&gt;
However, since starting the default initscript (/etc/init.d/openvpn) will cause a failure if no file named openvpn.conf is present, I'd strongly recommend to delete it from the default runlevel  ;)
&lt;/p&gt;
&lt;p&gt;
This is caused by the init script itself, as it determines the config solely by its name. Therefore the default initscript (/etc/ini.d/openvpn) will look for the aforementioned config file (/etc/openvpn/openvpn.conf) and report an error if it couldn't be found.
&lt;/p&gt;
&lt;p&gt;
To start the tunnel on boot, the usual &lt;em&gt;rc-update&lt;/em&gt; call will do the trick.
&lt;/p&gt;

Cheers!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-173498278986028431?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/173498278986028431/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/multiple-vpn-tunnels-gentoo-style.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/173498278986028431'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/173498278986028431'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/multiple-vpn-tunnels-gentoo-style.html' title='Multiple VPN Tunnels, Gentoo Style'/><author><name>phlo</name><uri>http://www.blogger.com/profile/02398237688787915749</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-6099874108542898216</id><published>2010-02-01T06:02:00.000-08:00</published><updated>2010-02-22T02:44:56.064-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='awk'/><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><title type='text'>favorite man pages</title><content type='html'>&lt;p&gt;I wondered what my favorite man pages would be. A little awk'ing shows it:

&lt;p&gt;&lt;pre&gt;
26 man bash
9 man find
8 man sed
8 man mplayer
8 man itoa
8 man dot
8 man cpio
7 man sleep
6 man read
6 man maxima
5 man xterm
5 man wget
5 man bc
5 man awk
4 man transcode
4 man sprintf
4 man script
4 man scp
4 man pushd
4 man popd
4 man ncftp
4 man latexmk
4 man gimp
4 man basename
3 man sudoers
3 man grep
3 man gcal
3 man cut
2 man wc
2 man units
2 man tee
2 man shutdown
2 man sh
2 man set
2 man pdfcrop
2 man paste
2 man netstat
2 man join
2 man cat
2 man cal
1 man wodim
1 man watch
1 man uname
1 man trap
1 man tar
1 man tail
1 man select
1 man quote
1 man profile
1 man patch
1 man nc
1 man mplayer 
1 man lsof
1 man ln
1 man hexdump
1 man head
1 man git-tag
1 man git-gui 
1 man git-commit
1 man git
1 man getopt
1 man fdevopen
1 man emacs
1 man display
1 man dijkstra
1 man diff
1 man convert
1 man col
1 man cmp
1 man ImageMagick
&lt;/pre&gt;

&lt;p&gt;This is the output of:

&lt;p&gt;&lt;pre class="prettyprint"&gt;
awk '/^man / { cmds[$i] ++ } END { for (i in cmds) print cmds[i] " " i }' .bash_history | sort -nr
&lt;/pre&gt;

&lt;p&gt;My bash history is configured as:

&lt;p&gt;&lt;pre class="prettyprint lang-bash" title=".bash_aliases"&gt;
export HISTCONTROL=erasedups
export HISTSIZE=10000
shopt -s histappend
&lt;/pre&gt;

&lt;p&gt;It would probably look a lot different if &lt;code&gt;erasedups&lt;/code&gt; would not be set.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-6099874108542898216?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/6099874108542898216/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/favorite-man-pages.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/6099874108542898216'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/6099874108542898216'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/02/favorite-man-pages.html' title='favorite man pages'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-2843671628838284560</id><published>2010-01-30T11:46:00.001-08:00</published><updated>2010-01-30T12:32:03.320-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>Unison</title><content type='html'>Unison is still maybe the only free and useable unidictional synchronisation tool out there, tho itself far from perfect (mind-boggling stupid sometimes). Here's a little script, which makes usage more practical. The basic setup is, that the user stores all his synced data in ~/data and will syncronize to a central node with unison over ssh. The remote server stores it's synced data on an encrypted partition, which is only unlocked while syncronization is in progress. Note that one node doesn't have to sync to the entire share. You can specify a subset in the dirlist (and also matching templates, so new directories will be added automatically).


&lt;p&gt;&lt;pre class="prettyprint lang-bash"&gt;
#!/bin/bash

#configuration
host="remote.host.org"
localdir="/home/user/data/"
remotedir="/srv/sync/data/"

#objects to sync
subdirs="foodir
bardir
buz/bum
`cd $localdir &amp;&amp; ls -d moo/bar/be*`
"
#subdirs="`cd $localdir &amp;&amp; ls -d *`"


read -s -p "Passowrd: "
pass=$REPLY
if ! ssh "$host" sudo mount_sync.sh -m &amp;lt&amp;ltEOF  ###!!!!! cms error with brackets
$pass
EOF
then
    echo "ABORTING: Remote mount failed." 
#exit 1
fi

for dir in $subdirs
do
    unison-2.13.16 -rsync -perms -1 -path $dir "$localdir" ssh://"$host"/"$remotedir"
    echo "$localdir"$dir ssh://"$host"/"$remotedir"$dir
done

if ! ssh "$host" sudo mount_sync.sh -u
then
    echo "WARNING: Closing crypted partition failed!!!"
    exit 1
fi
&lt;/pre&gt;

On the server side, you need a script to open the partition and mount it (mount_sync.sh), something like this will do.

&lt;p&gt;&lt;pre class="prettyprint lang-bash"&gt;
#!/bin/bash

# configution
encdev="/dev/sdb1"
mountdir="/srv/sync/"


if [ "$1" = "-m" ]
then
    if [ ! -b $encdev ]
    then
        echo "ABORTING: Can't find block device" $encdev
        exit 1
    fi

    if ! cryptsetup isLuks $encdev
    then
        echo "ABORTING: Device doesn't include a lux partition."
        exit 1
    fi

    if ! cryptsetup luksOpen $encdev sync_part0
    then
        echo "ABORTING: Failed to open ecrypted device."
        exit 1
    fi

    if ! mount /dev/mapper/sync_part0 $mountdir
    then
        echo "ABORTING: Mount failed."
        exit 1
    fi
fi

if [ "$1" = "-u" ]
then
    if ! umount $mountdir
    then
        echo "ABORTING: Failed to unmount."
        exit 1
    fi

    if ! cryptsetup luksClose sync_part0
    then
        echo "ABORTING: Failed to close encrypted disc"
        exit 1
    fi
fi
&lt;/pre&gt;

And a sudoers config to allow this script for your login user.

&lt;p&gt;&lt;pre class="prettyprint"&gt;
loginuser   ALL=NOPASSWD: /bin/mount_sync.sh
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-2843671628838284560?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/2843671628838284560/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/unison.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/2843671628838284560'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/2843671628838284560'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/unison.html' title='Unison'/><author><name>DD</name><uri>http://www.blogger.com/profile/09516860909544238970</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-7155584933427102601</id><published>2010-01-30T06:05:00.000-08:00</published><updated>2010-01-30T06:09:09.533-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='gentoo'/><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><title type='text'>gentoo: list installed packages</title><content type='html'>&lt;p&gt;This commandline lists the installed packages (with version) and prefixes every entry with an '=':

&lt;p&gt;&lt;pre class="prettyprint"&gt;
find /var/db/pkg -maxdepth 2 -mindepth 2 | sed -e 's/^\/var\/db\/pkg\//=/'
&lt;/pre&gt;

&lt;p&gt;The output looks like that:

&lt;p&gt;&lt;pre&gt;
=sys-devel/automake-1.9.6-r2
=sys-devel/autoconf-2.63-r1
=sys-devel/icecream-0.9.2
=sys-devel/automake-wrapper-3-r1
=sys-devel/bison-2.3
&lt;/pre&gt;

&lt;p&gt;&lt;div class="configbox"&gt;&lt;ul&gt;
&lt;li&gt;Gentoo 10.0 Desktop
&lt;/ul&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-7155584933427102601?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/7155584933427102601/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/gentoo-list-installed-packages.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/7155584933427102601'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/7155584933427102601'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/gentoo-list-installed-packages.html' title='gentoo: list installed packages'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-8771436098504273119</id><published>2010-01-27T13:36:00.000-08:00</published><updated>2010-01-27T14:20:21.650-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='vim'/><title type='text'>Different Color Schemes per Terminal in VIM</title><content type='html'>I use fluxbox as an window manager and use different terminal settings, looks and fonts for different working situations. Something I found pretty useful is to also adapt parts of my vim config and colorscheme to these settings. So I got different shortcuts for terminals with for e.g. big dark on white and one with small white on black letters. Based on those I set different vim color schemes. Nothing fancy, but still,... Just export an environment variable before you execute the terminal and check in vimrc. For e.g. in a fluxbox keys file:

&lt;p&gt;&lt;pre class="prettyprint lang-bash"&gt;
Mod4 g :ExecCommand export VIMCLS=dark &amp;&amp; gnome-terminal
&lt;/pre&gt;

And in a vimrc

&lt;p&gt;&lt;pre class="prettyprint lang-bash"&gt;
if "$VIMCLS" == "dark"
    set t_Co=256
    colorscheme Mustang_Vim_Colorscheme_by_hcalves
endif
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-8771436098504273119?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/8771436098504273119/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/different-color-schemes-per-terminal-in.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/8771436098504273119'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/8771436098504273119'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/different-color-schemes-per-terminal-in.html' title='Different Color Schemes per Terminal in VIM'/><author><name>DD</name><uri>http://www.blogger.com/profile/09516860909544238970</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-401561854602640796</id><published>2010-01-25T17:24:00.000-08:00</published><updated>2010-01-25T17:46:05.684-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>Booting on x86</title><content type='html'>Just the absolute basic stuff you need to boot on any x86 hardware (or in this case in qemu). For more info see &lt;a href="http://wiki.osdev.org/Bare_Bones"&gt;osdev wiki&lt;/a&gt;. You will need the following files:
&lt;ul&gt;&lt;li&gt;linker.ld -- to configure your ld&lt;/li&gt;&lt;li&gt;loader.s  -- loader&lt;/li&gt;&lt;li&gt;kernel.c  -- kmain&lt;/li&gt;&lt;li&gt;grub/stage1&lt;/li&gt;&lt;li&gt;grub/stage2&lt;/li&gt;&lt;/ul&gt;Copy the linker.ld and loader.s files from the osdev wiki page. A simple kernel.c, which would write to the framebuffer could look like this:

&lt;p&gt;&lt;pre class="prettyprint lang-c"&gt;
#define CBLACK 0x00
#define CBLUE  0x01
#define CGREEN 0x02
#define LIGHT(x)  ((x)+8)

void clear_screen() {
    unsigned char *vr = (unsigned char *) 0xb8000;
    for (int i=0; i&lt;4000; i+=2) {
        *(vr + i) = 0;
    }
}

void print(char *text, int x, int y, unsigned char fcolour, unsigned char bcolour) {
    unsigned char *vr = (unsigned char *) 0xb8000;
    vr = vr + (y*160) + (x*2);
    for (int i=0; *text; i+=2,text++) {
        *(vr + i) = *text;
        *(vr + i+1) = (bcolour &lt;&lt; 4) | (fcolour &amp; 0x0F);
    }
}

void kmain( void* mbd, unsigned int magic ) {
    clear_screen();
    print("Kernel is running now,...", 7, 3, LIGHT(CGREEN), CBLACK);
}
&lt;/pre&gt;

Now you need grub stage1 and stage2, you can grab these from most linux distros in /boot/grub/. To get this running now, here's a little shell script.

&lt;p&gt;&lt;pre class="prettyprint lang-bash"&gt;
#!/bin/bash

############# CONFIG ###############
IMAGENAME="myos.img"

#the grup bins
STAGE1="grub/stage1"
STAGE2="grub/stage2"

#kernel starting block
KBLOCK=220
###################################

function ceil() {
        par=$1
        c=${par/.*}
        echo $(($c+1))
}


#build
nasm -f elf -o loader.o loader.s
gcc -std=c99 -c kernel.c -o kernel.o -Wall -nostdlib -nostartfiles -nodefaultlibs

#link
ld -T linker.ld -o kernel.bin loader.o kernel.o

#create pad
read STAGE1_SIZE varfoo&lt;&lt;&lt;`du -bs $STAGE1`
read STAGE2_SIZE varfoo&lt;&lt;&lt;`du -bs $STAGE2`
GRUB_SIZE=$(($STAGE1_SIZE+$STAGE2_SIZE))
BKB_SIZE=$(($KBLOCK*512))
PAD_SIZE=$(($BKB_SIZE-$GRUB_SIZE))

dd if=/dev/zero of=pad bs=$PAD_SIZE count=1 &amp;&gt; /dev/null

#make image
cat grub/stage1 grub/stage2 pad kernel.bin &gt; $IMAGENAME

#print grub commands
read KERNEL_SIZE varfoo&lt;&lt;&lt;`du -bs kernel.bin`
KERNEL_BLOCKS=`echo "scale=2; "$KERNEL_SIZE"/512"|bc`
KERNEL_BLOCKS=`ceil $KERNEL_BLOCKS`
echo ---------------------------
echo Now enter on GRUB cmd line:
echo kernel $KBLOCK+$KERNEL_BLOCKS
echo boot
echo ---------------------------

#run qemu
qemu  -boot a -fda $IMAGENAME
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-401561854602640796?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/401561854602640796/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/booting-on-x86.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/401561854602640796'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/401561854602640796'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/booting-on-x86.html' title='Booting on x86'/><author><name>DD</name><uri>http://www.blogger.com/profile/09516860909544238970</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-5453767010100566140</id><published>2010-01-25T15:58:00.002-08:00</published><updated>2010-01-25T16:18:25.514-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='network'/><category scheme='http://www.blogger.com/atom/ns#' term='sed'/><title type='text'>get ip of interface</title><content type='html'>&lt;p&gt;The IP of an interface? Nothing easier than that:

&lt;p&gt;&lt;pre&gt;
ifconfig wlan1 | sed -n -e 's/.*inet addr:\([0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+\).*/\1/p;d'
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-5453767010100566140?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/5453767010100566140/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/get-ip-of-interface.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/5453767010100566140'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/5453767010100566140'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/get-ip-of-interface.html' title='get ip of interface'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-5258166168951259325</id><published>2010-01-25T15:58:00.001-08:00</published><updated>2010-01-25T16:17:22.091-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='network'/><category scheme='http://www.blogger.com/atom/ns#' term='sed'/><title type='text'>get default interface</title><content type='html'>&lt;p&gt;If one want's to know which interfaces is connected to the default gateway, one might find out:



&lt;p&gt;&lt;pre&gt;
route -n | sed -n -e 's/^0.0.0.0\(.*[[:blank:]]\)\+\([a-z0-9]\+\)/\2/p' 
&lt;/pre&gt;

&lt;p&gt;or


&lt;p&gt;&lt;pre&gt;
route -n | grep -E "^0.0.0.0" | sed -e 's/[[:blank:]]\+/ /g' | cut -d' ' -f8
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-5258166168951259325?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/5258166168951259325/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/get-default-interface.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/5258166168951259325'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/5258166168951259325'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/get-default-interface.html' title='get default interface'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-8464024873491626044</id><published>2010-01-25T15:25:00.000-08:00</published><updated>2010-01-25T15:38:57.580-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='network'/><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>Bluesocket Login</title><content type='html'>Many WLAN hotspots or networks will redirect any http request, after you connected, to some sort of login page or legal disclaimer. Here is a short script which will authenticate to bluesocket, a "widely-used proprietary wlan managment solution".

&lt;p&gt;&lt;pre class="prettyprint lang-bash"&gt;
#!/bin/bash

IP=`ifconfig wlan0 |grep "inet addr:"|cut -d: -f2|cut -d\  -f1`
USER="username"
PASS="password"

curl -d require_terms_g="1" -d bs_name=${USER} -d bs_password=${PASS} \
-d _FORM_SUBMIT=1 -d which_form=reg -d source=${IP} https://loginpage.foo/login.pl &amp;&gt; /dev/null
&lt;/pre&gt;

You may not require the variable require_terms_g.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-8464024873491626044?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/8464024873491626044/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/bluesocket-login.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/8464024873491626044'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/8464024873491626044'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/bluesocket-login.html' title='Bluesocket Login'/><author><name>DD</name><uri>http://www.blogger.com/profile/09516860909544238970</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-1310105330592909300</id><published>2010-01-25T14:51:00.000-08:00</published><updated>2010-01-25T15:24:18.946-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='network'/><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>Get IP</title><content type='html'>A simple script, which parses the content from, whatismyip.com and prints out the IP address. Is compatible with busybox (sh, nc, tail), to be used on embedded systems.

&lt;pre class="prettyprint lang-bash"&gt;
#!/bin/sh

get_ip_() {
    busybox nc www.whatismyip.com 80 &lt;&lt; EOF
GET /automation/n09230945.asp HTTP/1.0
User-Agent: netcat
Accept: */*
Host: www.whatismyip.com
Connection: close

  
EOF
}
get_ip() {
    get_ip_ |tail -1
}

get_ip
echo
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-1310105330592909300?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/1310105330592909300/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/simple-script-which-parses-content-from.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/1310105330592909300'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/1310105330592909300'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/simple-script-which-parses-content-from.html' title='Get IP'/><author><name>DD</name><uri>http://www.blogger.com/profile/09516860909544238970</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-1572486039843508888</id><published>2010-01-25T09:49:00.000-08:00</published><updated>2010-05-27T17:10:06.587-07:00</updated><title type='text'>posting tips</title><content type='html'>Since this blog engine is really stupid and bad, a few special settings had to be set:

&lt;ul&gt;
&lt;li&gt;only html editor available
&lt;li&gt;no automatic &lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt; - use &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; instead!
&lt;li&gt;when posting code, use the &lt;code&gt;&amp;lt;pre class="prettyprint"&amp;gt;&lt;/code&gt; tag. The tag can also contain the language, &lt;code&gt;class="prettyprint lang-bash"&lt;/code&gt; for example.
&lt;pre class="prettyprint lang-html"&gt;
&amp;lt;p&amp;gt;&amp;lt;pre class="prettyprint lang-bash"&amp;gt;
#! /bin/bash
do_something_here
&amp;lt;/pre&amp;gt;
&lt;/pre&gt;

&lt;li&gt;if the code contains symbols that would be interpeted as HTML, (&amp;lt;, &amp;gt;, &amp;amp;,...) use CDATA around the code:
&lt;pre class="prettyprint lang-html"&gt;
&amp;lt;p&amp;gt;&amp;lt;pre class="prettyprint lang-bash"&amp;gt;&amp;lt;![CDATA[
#! /bin/bash
do_something_here &amp;lt;&amp;lt;EOF
something
EOF
]]&amp;gt;&amp;lt;/pre&amp;gt;
&lt;/pre&gt;

&lt;li&gt;for keyboard inputs, use the &lt;code&gt;&amp;lt;kbd&amp;gt;&lt;/code&gt; tag.
&lt;li&gt;the "Configuration" block at the end of some posts is written like that:
&lt;pre class="prettyprint lang-html"&gt;
&amp;lt;p&amp;gt;&amp;lt;div class="configbox"&amp;gt;
&amp;lt;ul&amp;gt;
&amp;lt;li&amp;gt; Linux knuth 2.6.31-gentoo-r6 #1 SMP Thu Nov 26 18:01:11 CET 2009 i686 Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz GenuineIntel GNU/Linux
&amp;lt;li&amp;gt; GNU bash, version 4.0.35(2)-release (i686-pc-linux-gnu)
&amp;lt;li&amp;gt; lircd 0.8.5
&amp;lt;/ul&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
&lt;/ul&gt;

hf!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-1572486039843508888?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/1572486039843508888/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/posting-guidelines.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/1572486039843508888'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/1572486039843508888'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/posting-guidelines.html' title='posting tips'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-7552822421965578520</id><published>2010-01-25T06:33:00.000-08:00</published><updated>2010-05-27T17:10:47.001-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='network'/><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><title type='text'>Random mac per day and device</title><content type='html'>This bash script lets you select a random mac address per day and device. I found useful in many networks, which require authentication and lock a session to one mac address.

&lt;pre class="prettyprint lang-bash"&gt;
#!/bin/bash

#------------------------------------------------#
# Aurel, 20 May 2008                             #
#------------------------------------------------#
# This script chooses a random mac but only one  #
# per day.                                       #
# Usage: changemac &lt;devicename&gt;                  #
#------------------------------------------------#
# Copyrigth: public domain                       #
#------------------------------------------------#

# configuration
logfile="/var/log/todays_mac_"

device=$1

if [ ! -f $logfile$device ]
then
    touch $logfile$device
    echo none &gt; $logfile$device
fi

if read -r line
then
    mac_day=`echo "$line"|cut -d\  -f1`
    mac_address=`echo "$line"|cut -d\  -f2`
    today=`date "+%j"`

    if [ "$mac_day" = "$today" ]
    then
        macchanger -m  $mac_address $device
    else
        macchanger -r $device
        cmac=`macchanger -s $device|cut -d\  -f3`
        echo `date "+%j"` $cmac &gt; $logfile$device
    fi
fi &lt; $logfile$device
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-7552822421965578520?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/7552822421965578520/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/random-mac-per-day-and-device.html#comment-form' title='1 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/7552822421965578520'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/7552822421965578520'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/random-mac-per-day-and-device.html' title='Random mac per day and device'/><author><name>DD</name><uri>http://www.blogger.com/profile/09516860909544238970</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-1254025987746129710</id><published>2010-01-24T05:27:00.000-08:00</published><updated>2010-02-22T02:52:30.373-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='graph theory'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><title type='text'>tarjans algorithm to find SCC's in digraphs</title><content type='html'>&lt;p&gt;An implementation of Tarjan's algorithm in &lt;code&gt;python&lt;code&gt;:

&lt;p&gt;&lt;pre class="prettyprint lang-python" title="tarjan.py"&gt;
#! /usr/bin/python

# mru, 2010

# tarjan's algorithm to find strongly connected components, as
# presented in "Algorithms in C++" by Sedgewick.

# example graph:
nodes = range(10)
graph = [ 
    (0, 1), (0, 6), (0, 8), 
    (1, 1), (1, 7), (1, 2),
    (2, 7), (2, 3),
    (3, 4), (3, 7),
    (4, 5),
    (5, 6), 
    (6, 4),
    (7, 6), (7, 3),
    (8, 9), 
    (9, 8), (9, 5)]

def scr(w):

    global cnt, low, id, pre, scnt, S

    low[w] = cnt
    pre[w] = cnt
    min = cnt
    cnt = cnt + 1

    S.append(w)
    
    for t in [ t for (s,t) in graph if s == w ]:
        if pre[t] == -1:
            scr(t)
        if low[t] &lt; min: 
            min = low[t]

    if min &lt; low[w]:
        low[w] = min
        return

    t = S.pop()
    id[t] = scnt
    low[t] = len(nodes)

    while t != w:
        t = S.pop()
        id[t] = scnt
        low[t] = len(nodes)
    
    scnt = scnt + 1

S = []
cnt = 0
scnt = 0
pre = [ -1 ] * len(nodes)
low = [ 0 ] * len(nodes)
id = [ 0 ] * len(nodes)

for i in nodes:
    if pre[i] == -1:
        scr(i)

for index in range(max(id)+1):
    print "nodes in scc ", index, ": ", [ j for (i,j) in map(None, id, nodes) if i == index ]
&lt;/pre&gt;

&lt;p&gt;The output looks like this:
&lt;p&gt;&lt;pre&gt;
nodes in scc  0 :  [4, 5, 6]
nodes in scc  1 :  [3, 7]
nodes in scc  2 :  [2]
nodes in scc  3 :  [1]
nodes in scc  4 :  [8, 9]
nodes in scc  5 :  [0]
&lt;/pre&gt;

&lt;p&gt;The example graph in the code corresponds to this graph:
&lt;p&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_vzQFbYjId3A/S1xMuj5KJBI/AAAAAAAAADA/77kRkujk2_s/s1600-h/tarjan.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 154px; height: 320px;" src="http://3.bp.blogspot.com/_vzQFbYjId3A/S1xMuj5KJBI/AAAAAAAAADA/77kRkujk2_s/s320/tarjan.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5430299613494649874" /&gt;&lt;/a&gt;


&lt;p&gt;The algorithm is taken from the very good book "Algorithms in C++" by Sedgewick, therefore the implementation style is not very python-styled.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-1254025987746129710?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/1254025987746129710/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/tarjans-algorithm-to-find-sccs-in.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/1254025987746129710'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/1254025987746129710'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/tarjans-algorithm-to-find-sccs-in.html' title='tarjans algorithm to find SCC&apos;s in digraphs'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_vzQFbYjId3A/S1xMuj5KJBI/AAAAAAAAADA/77kRkujk2_s/s72-c/tarjan.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-6715514750847480046</id><published>2010-01-23T06:15:00.000-08:00</published><updated>2010-02-21T19:37:53.080-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><category scheme='http://www.blogger.com/atom/ns#' term='lirc'/><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><title type='text'>poweroff with lirc</title><content type='html'>&lt;p&gt;I keep trying to use my remote control to do things, but i always forget where i put it.

&lt;p&gt;Anyways, i did this little scriptie to power off my computer when i press a remote-control button several times within a specified time period.

&lt;p&gt;&lt;pre class="prettyprint lang-bash" title="poweroff_after_mplayer.sh"&gt;
#! /bin/bash

# use with irexec
# if a button was pressed N times with less the DT seconds between 
# the presses, EXEC will be executed

# mru, dez 2009


SAVE="$HOME/.lirc-poweroff"
UPTIME="$(cut -d' ' -f1 /proc/uptime)"
EXEC="sudo shutdown -h +5"

DT=1
N=2

touch "$SAVE"

while read LAST; do

 RES=$(bc &lt;&lt;&lt; "scale=10; ($UPTIME-$LAST) &gt; $DT")

 if [ "$RES" == "1" ]; then
  : &gt; "$SAVE"
  break
 elif (( "$N" == 0 )); then
  $EXEC
  : &gt; "$SAVE"
  exit 0
 fi

 N=$(( $N - 1 ))

done &lt; "$SAVE"
  
echo "$UPTIME" &gt;&gt; "$SAVE"
&lt;/pre&gt;

&lt;p&gt;The script creates a file &lt;code&gt;$SAVE&lt;/code&gt; and stores the time when the button was pressed last time. If a subsequent press is close (in respect to &lt;code&gt;$DT&lt;/code&gt;), the entry will be appended to the file. If the file reaches a linecount of &lt;code&gt;$N&lt;/code&gt;, &lt;code&gt;$EXEC&lt;/code&gt; will be executed.

&lt;p&gt;Here is the entry in my &lt;code&gt;~/.lircrc&lt;/code&gt;:

&lt;p&gt;&lt;pre&gt;
begin
  button = KEY_BACK
  prog = irexec
  config = ~/bin/lirc-poweroff.sh
  repeat = 0
end
&lt;/pre&gt;

&lt;p&gt;&lt;div class="configbox"&gt;
&lt;ul&gt;
&lt;li&gt; Linux knuth 2.6.31-gentoo-r6 #1 SMP Thu Nov 26 18:01:11 CET 2009 i686 Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz GenuineIntel GNU/Linux
&lt;li&gt; GNU bash, version 4.0.35(2)-release (i686-pc-linux-gnu)
&lt;li&gt; lircd 0.8.5
&lt;/ul&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-6715514750847480046?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/6715514750847480046/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/poweroff-with-lirc.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/6715514750847480046'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/6715514750847480046'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/poweroff-with-lirc.html' title='poweroff with lirc'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-7761173661602303867</id><published>2010-01-23T05:24:00.000-08:00</published><updated>2010-01-23T11:50:54.859-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='media'/><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><category scheme='http://www.blogger.com/atom/ns#' term='make'/><title type='text'>jpg to avi</title><content type='html'>Wouldn't it be nice if one could easily convert a bunch of jpegs to a .avi movie?

Have a look at that:

&lt;pre class="prettyprint lang-make"&gt;
#! /usr/bin/make -f                                                                                                                         

# mru, 2009-04-05                                                                                                                           

# make [TARGET=output.avi] [PATTERN='*.jpg'] [SOUND=] [FPS=20]                                                                              

# you have to define TARGET and PATTERN on cli                                                                                              
# SOUND is optional; not defined -&gt; not used                                                                                                
#                                                                                                                                           
# FPS..     frames per second  [ default = 20 ]                                                                                             
# TARGET..  output file name for avi [ output.avi ]                                                                                         
# PATTERN.. wildcard for all jpegs to use [ *.jpg ]                                                                                         
# SOUND..   filename of .wav file as soundtrack  [ optional ]                                                                               

# make play [TARGET=output.avi]                                                                                                             
# make clean                                                                                                                                
# make resize [RESOLUTION=1024x768] [-j 4]                                                                                                  


# requires MJPEG tools                                                                                                                      


FPS = 20
PATTERN = *.jpg
TARGET = output.avi
RESOLUTION = 1024x768

all: play
    ls -lah $(TARGET)

# creates a string with newline between every element of wordlist on stdin                                                                  
MAKENEWLINE = tr " " "\n"
FILELIST = $(wildcard $(PATTERN))

%.avi: $(FILELIST)
    @tr ' ' '\n' &lt;&lt;&lt; "$?" | jpeg2yuv -v 0 -I p -f $(FPS) | yuv2lav -f a -b 10000 -o silent.avi
ifdef SOUND
    @lavaddwav silent.avi $(SOUND) $@ 
    @rm silent.avi
else
    @mv silent.avi $@
endif


play: $(TARGET)
    @mplayer $(TARGET)

clean:
    @rm -f $(TARGET)

resize: $(FILELIST:.jpg=.res)

# i love makefile parallelism, try -j 4 !!!                                                                                                 
%.res: %.jpg
    convert $&lt; -resize $(RESOLUTION) $&lt;

.PHONY: all play clean resize
&lt;/pre&gt;


&lt;div class="configbox"&gt;
&lt;ul&gt;
&lt;li&gt; Linux knuth 2.6.31-gentoo-r6 #1 SMP Thu Nov 26 18:01:11 CET 2009 i686 Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz GenuineIntel GNU/Linux
&lt;li&gt; GNU bash, version 4.0.35(2)-release (i686-pc-linux-gnu)
&lt;li&gt; GNU Make 3.81
&lt;/ul&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-7761173661602303867?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/7761173661602303867/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/jpg-to-avi.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/7761173661602303867'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/7761173661602303867'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/jpg-to-avi.html' title='jpg to avi'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-9007777226594800274</id><published>2010-01-23T05:19:00.000-08:00</published><updated>2010-05-27T16:42:38.504-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><title type='text'>makeclean: clean typical temporary files</title><content type='html'>&lt;p&gt;I often want to &lt;code&gt;clean&lt;/code&gt; my home directory, just to get rid of all the temporary files i left during my escapades.

&lt;p&gt;This script does it nicely, informative and interactive:

&lt;p&gt;&lt;pre class="prettyprint lang-bash"&gt;
#! /bin/bash                                                                                                                                

# mru, 2009-something                                                                                                                       

# typical clean situation... erase temp, bak - files, recursively from                                                                      
# the current directory.                                                                                                                    
#                                                                                                                                           
# which files to delete is configured in the variable FILTER:                                                                               

FILTER=("*.aux" "*~" "*.bak")



# i can't use the globbing, turn it off                                                                                                     
set -f

join_cond() {
    echo -name "${FILTER[0]}";
    for i in $(seq 1 $((${#FILTER[@]} - 1))); do
        echo -or -name "${FILTER[i]}"
    done
}

FILES=$(find . "(" $(join_cond) ")" -print )

if [ -z "$FILES" ]; then
    echo "No files to clean found. Stopping."
    exit 0
fi

echo "Considering these files:"
echo

while read filename; do
    echo " - $filename"
done &lt;&lt;&lt; "$FILES"

read -p "really delete [y/N]?"
if [ "$REPLY" == "y" ]; then
    while read filename; do
        rm -v "$filename"
    done &lt;&lt;&lt; "$FILES"
    echo "Done"
else
    echo "Cancelled"
fi
&lt;/pre&gt;

&lt;div class="configbox"&gt;
&lt;ul&gt;
&lt;li&gt; Linux knuth 2.6.31-gentoo-r6 #1 SMP Thu Nov 26 18:01:11 CET 2009 i686 Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz GenuineIntel GNU/Linux
&lt;li&gt; GNU bash, version 4.0.35(2)-release (i686-pc-linux-gnu)
&lt;/ul&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-9007777226594800274?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/9007777226594800274/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/clean-typical-temporary-files.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/9007777226594800274'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/9007777226594800274'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/clean-typical-temporary-files.html' title='makeclean: clean typical temporary files'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-6933348399546429578</id><published>2010-01-23T05:01:00.000-08:00</published><updated>2010-05-27T17:07:38.409-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><category scheme='http://www.blogger.com/atom/ns#' term='sed'/><title type='text'>sed on multiple files</title><content type='html'>To replace strings in multiple files, i use this commandline:

&lt;p&gt;
&lt;kbd&gt;
sed -e $EXP -i $FILEGLOB
&lt;/kbd&gt;

&lt;p&gt;
For example:

&lt;p&gt;
&lt;kbd&gt;
sed -e 's/old_identifier/new_identifier/g' -i *.c
&lt;/kbd&gt;

&lt;p&gt;It will execute the expression on every file, performing inplace changes (= &lt;code&gt;-i&lt;/code&gt;). An optional backup argument could be supplied to the &lt;code&gt;-i&lt;/code&gt; argument to create backup files first.



&lt;p&gt;&lt;div class="configbox"&gt;
&lt;ul&gt;
&lt;li&gt; Linux knuth 2.6.31-gentoo-r6 #1 SMP Thu Nov 26 18:01:11 CET 2009 i686 Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz GenuineIntel GNU/Linux
&lt;li&gt; GNU sed version 4.2
&lt;/ul&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-6933348399546429578?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/6933348399546429578/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/sed-on-multiple-files.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/6933348399546429578'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/6933348399546429578'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/sed-on-multiple-files.html' title='sed on multiple files'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-8207646173623928241</id><published>2010-01-23T04:57:00.000-08:00</published><updated>2010-01-25T05:55:28.511-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><category scheme='http://www.blogger.com/atom/ns#' term='media'/><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><title type='text'>poweroff after mplayer</title><content type='html'>&lt;p&gt;For those who use the non-gui version of &lt;code&gt;mplayer&lt;/code&gt; and like to junk movies before bed-time it might be useful to shutdown the computer when the movie is done. I do this with this little script:

&lt;p&gt;&lt;pre class="prettyprint lang-bash"&gt;
#! /bin/bash                                                                    

while pidof mplayer; do
        sleep 1
done

sudo poweroff
&lt;/pre&gt;

&lt;p&gt;As soon as &lt;code&gt;mplayer&lt;/code&gt; quits, the computer will shut down.

&lt;p&gt;Clearly, the user must be allowed to &lt;code&gt;sudo&lt;/code&gt; the &lt;code&gt;poweroff&lt;/code&gt; command.


&lt;p&gt;Another way to do it would be something like this:
&lt;p&gt;&lt;kbd class="prettyprint lang-bash"&gt;
watch "pidof mplayer || (poweroff; kill -15 $$)"
&lt;/kbd&gt;
&lt;p&gt;But who would take the easy way?

&lt;p&gt;&lt;div class="configbox"&gt;
&lt;ul&gt;
&lt;li&gt; Linux knuth 2.6.31-gentoo-r6 #1 SMP Thu Nov 26 18:01:11 CET 2009 i686 Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz GenuineIntel GNU/Linux
&lt;li&gt; GNU bash, version 4.0.35(2)-release (i686-pc-linux-gnu)
&lt;li&gt; MPlayer SVN-r29796-4.3.4 (C) 2000-2009 MPlayer Team
&lt;/ul&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-8207646173623928241?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/8207646173623928241/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/poweroff-after-mplayer.html#comment-form' title='1 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/8207646173623928241'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/8207646173623928241'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/poweroff-after-mplayer.html' title='poweroff after mplayer'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-774059900457406820</id><published>2010-01-23T04:49:00.000-08:00</published><updated>2010-01-24T07:30:28.483-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><category scheme='http://www.blogger.com/atom/ns#' term='sed'/><title type='text'>removing ansi escape codes from typescript</title><content type='html'>&lt;p&gt;I like using the &lt;code&gt;script&lt;/code&gt; tool, included in the &lt;code&gt;util-linux-ng&lt;/code&gt; project, &lt;a href="http://www.kernel.org/pub/linux/utils/util-linux-ng/"&gt;http://www.kernel.org/pub/linux/utils/util-linux-ng/&lt;/a&gt;.

&lt;p&gt;But all the escape codes make the files unreadable in less, for example.

&lt;p&gt;This small sed script removes some escape codes. I did not search for a spec of the codes, so i don't know what all could get wrong:

&lt;p&gt;&lt;pre class="prettyprint"&gt;
#! /bin/sed -f

# removes escape sequences from "script" typescripts
# read about "util-linux[-ng]" for more info
 
# consider using -i to filter "in-place"
# `man script` for more information...
 
# mru, dez. 2009

s/\r//g
s/^[\]0;//g
s/^G//g
s/^[\[\(\([[:digit:]]*;\|?\)\?[[:digit:]]*\)\?[Kmh]//g
&lt;/pre&gt;

&lt;p&gt;Something is missing: the output will be wrong for some inputs. The codes for &lt;code&gt;Ctrl-C&lt;/code&gt;, &lt;code&gt;Ctrl-W&lt;/code&gt;, ... should be interpreted to reconstruct the real output as seen in the shell. Well, nothing is perfect. I think the tool &lt;code&gt;col&lt;/code&gt; (also &lt;code&gt;util-linux-ng&lt;/code&gt; would do the job. &lt;code&gt;man col&lt;/code&gt; would give the details.


&lt;p&gt;&lt;div class="configbox"&gt;
&lt;ul&gt;
&lt;li&gt; Linux knuth 2.6.31-gentoo-r6 #1 SMP Thu Nov 26 18:01:11 CET 2009 i686 Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz GenuineIntel GNU/Linux
&lt;li&gt; GNU sed version 4.2
&lt;/ul&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-774059900457406820?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/774059900457406820/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/removing-ansi-escape-codes-from.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/774059900457406820'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/774059900457406820'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/removing-ansi-escape-codes-from.html' title='removing ansi escape codes from typescript'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573311539006121754.post-5187404279644467747</id><published>2010-01-23T04:15:00.000-08:00</published><updated>2010-01-23T11:52:37.084-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='emacs'/><title type='text'>shared emacs config</title><content type='html'>One might want to share an emacs config across machines. An easy way to make conditional configuration would be to move machine specific configuration to another file, like &lt;code&gt;.emacs-local&lt;/code&gt;. This solution is not optimal for people like me that synchronize configs a lot.

A nicer solution follows. Emacs reads the &lt;code&gt;hostname&lt;/code&gt; and executes a block of code if an entry for that name exists:

&lt;pre&gt;&lt;code&gt;
(defun load-local-conf ()
  ;;  (interactive)
  (let ((host (system-name)))
    (cond ((string= host "mru-laptop")
           (set-default-font "-unknown-DejaVu Sans Mono-normal-normal-normal-*-16-*-*-*-m-0-iso10646-1"))
          ((string= host "knuth.olymp")
           (print "hello from knuth")))))

(load-local-conf)
&lt;/code&gt;&lt;/pre&gt;


Also, one could test for filenames with the hostname, lets say machine &lt;code&gt;knuth&lt;/code&gt; saves its Emacs config in &lt;code&gt;.emacs-knuth&lt;/code&gt;.

&lt;pre&gt;&lt;code&gt;
(defun load-local-conf ()
  (interactive)
  (let ((filename (concat "~/.emacs-" (system-name))))
    (if (file-readable-p filename)
        (load filename)
      nil)))
&lt;code&gt;&lt;/pre&gt;


&lt;div class="configbox"&gt;
&lt;ul&gt;
&lt;li&gt; Linux knuth 2.6.31-gentoo-r6 #1 SMP Thu Nov 26 18:01:11 CET 2009 i686 Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz GenuineIntel GNU/Linux
&lt;li&gt; GNU Emacs 23.1.1
&lt;/ul&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573311539006121754-5187404279644467747?l=automatenkaffee.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://automatenkaffee.blogspot.com/feeds/5187404279644467747/comments/default' title='Kommentare zum Post'/><link rel='replies' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/shared-emacs-config.html#comment-form' title='0 Kommentare'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/5187404279644467747'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573311539006121754/posts/default/5187404279644467747'/><link rel='alternate' type='text/html' href='http://automatenkaffee.blogspot.com/2010/01/shared-emacs-config.html' title='shared emacs config'/><author><name>mru</name><uri>http://www.blogger.com/profile/00812135266832152266</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
