fliegt raus

Ich betreibe ja seit langer Zeit meinen eigenen River of News, d.h. ein RSS Feed Reader hier auf der Seite. Der ist allerdings aus abmahnungstechnischen Gründen nicht mehr öffentlich, ich nutze ihn also nur privat, und zwar täglich.

Unter anderem habe ich den Feed von GEO im Reader. Da kommt nur selten was neues, und meistens ist es Unfug. Heute hab ich den Feed gelöscht, weil sich der Unfug echt nicht mehr steigern lässt. Was denken die sich dabei?!

2014-07-18 - Geo Unfug:

18 July 2014 | #river



If you're condemned to use sudo for systems administration on a daily basis you know the problem: working all the time with sudo is annoying. It's ok if you've got to enter sudo only here and there. But on some systems almost everything is only reachable via sudo.

At least it annoyed me, so I put the nightmare to an end. Autosudo consists of a couple of bash functions which - once enabled - learn each entered sudo command and create a temporary wrapper function for it so that you can leave "sudo" the next time you use the command. An example session:

[16.Jul 09:48:22] --- [~] ---
me@machine: % autosudo ena

[16.Jul 09:49:14] --- [~][autosudo]  ---
me@machine: % sudo less /var/log/splunk/ticket.log

+++ autosudo: added "less" to auto sudo commands +++

[16.Jul 09:50:32] --- [~][autosudo+1]  ---
me@machine: % less /var/log/splunk/ticket.log

[16.Jul 09:50:50] --- [~][autosudo+1]  ---
me@machine: % autosudo sh
+++ auto sudo enabled for:  less +++

[16.Jul 09:50:52] --- [~][autosudo+1]  ---
me@machine: % autosudo dis
+++ disabling auto sudo commands +++
    disabling less

[16.Jul 09:50:58] --- [~] ---
me@machine: % less /var/log/splunk/ticket.log
/var/log/splunk/ticket.log: Permission denied

What happens here? First, I enabled the feat with "autosudo ena". Next I called a sudo command "sudo less". Once completed the autosudo facility adds "less" as an autosudo wrapper and notifies me about it. From now on I can just use "less" instead of "sudo less" while achieving the same functionality. Finally I let it display a list of currently autosudo'ed commands ("autosudo sh") and then I disable it with "autosudo dis". Note that the plain "less" call in the end doesn't work anymore since after disabling autosudo "less" was not sudo wrapped anymore. Easy enough.

Here's the code:

autosudo () {
    # enable auto sudo
    case $1 in
            export AUTOSUDO=1
            export SUDOCMD=`type -p sudo`
            alias sudo=sudoexec
            unset AUTOSUDO
            unalias sudo
            echo "+++ disabling auto sudo commands +++"
            for cmd in $AUTOSUDOCMDS; do
                echo "    disabling $cmd"
                unset $cmd
            if test -n "$AUTOSUDO"; then
                echo "+++ auto sudo enabled for: $AUTOSUDOCMDS +++"
                echo "+++ auto sudo disabled +++"
            echo "Usage: autosudo <enable|disable|show>"

sudoexec () {
    # determine sudo cmd and if successfull, alias it away
    if test -n "$AUTOSUDO"; then
        if $SUDOCMD $*; then
            cmd=`echo "$*" | awk '{ print $1}'`
            if echo "$cmd" | egrep -v "^-" > /dev/null 2>&1; then
                cmd=`basename $cmd`
                cat <<EOF > $lambda
unalias $cmd
function        $cmd () {
  $SUDOCMD $cmd \$*
                export LAMBDA=$lambda
                AUTOSUDOCMDS="$AUTOSUDOCMDS $cmd"
                echo "+++ autosudo: added \"$cmd\" to auto sudo commands +++"

cleanlambda() {
    if test -n "$LAMBDA"; then
        rm -f $LAMBDA
        unset LAMBDA
PROMPT_COMMAND="if test -n \"\$LAMBDA\"; then source \$LAMBDA; cleanlambda; fi; PS1='\[\033]0;\u@$host:\w\007\]
\$(DATE) --- [\w]\$(SHAUTOSUDO)\$(JOBS) ---
\u@$host: $CURSOR '"

Some words about it: If you call "autosudo ena", then "sudo" will be made an alias to "sudoexec", one of the functions above. "sudoexec" then executes the sudo command as usual and if it returns success it extracts the command and puts it into a wrapper function which it writes into a temporary file. The filename gets exported into the variable $LAMBDA. The most important part is the extension to $PROMPT_COMMAND. I precede it with a little bit of code which looks for an environment variable $LAMBDA. If set it assumes it is a file and sources it. This makes the wrapper function available to the current bash environment.

16 July 2014 | #source


Review To The Stars (Harry Irons Trilogy)

These days I started to read a new book "To The Stars" (from Herry Irons Trilogy) by Thomas Stone. First of all, I'd like to note, that I particularly like the novel in that I can't stop reading it. The story is utterly fascinating and I want to know how it ends very bad.

However, there are so many painful errors in the book, it's a shame. And I'm only done with the first half of the first book.

First of all are the characters. They are mostly flat and thin, all of them out of the bag of a very limited number of stereotypes with the exception of Harry the main character. In most cases it's unclear what motivates the people in the story. Sometimes it is pure money, sometimes ... we don't know. They are also painted in contradictorily ways. While at the start of the story we learn that only the best of the best of society will be allowed to travel to the stars, we see later that almost everybody on board of a spaceship thinks only of one thing: the bonus. That's really annoying at times. For instance, there's some women who shall have a tremendous scientifical background. The first thing she says when encountering the very first alien race is about an additional bonus which she will get because of it. C'mon! Which scientist in the world doesn't have a minimum of curiosity?! And who does abandon her crewmates just to secure an extra bonus? Who would do that?

The overall dumpness is appalling. Just one example out of hundreds possible: Harry is there down on the surface and is confronted by three aliens. They wear sophisticated suits, well protected and use advanced weaponry, while Harry is unarmed (though he had a weapon but lost it earlier). He's got help by two native sentient beings (they are on stone age level). Together they manage to catch one of the aliens with a net, the alien looses its weapon, Harry takes it and disables the suit with it. Surely an advantage. Then the remaining aliens approach them and the three of them run away. In the process Harry dumps the weapon. Yes, literally. He dumps it away, he doesn't just loose it. Holy Mother Mary! Instead of running he could have just fired on the other aliens and the problem had be solved. But no. In this example you can clearly see, how Stone drives the story forward. Stupidity causes trouble, which they try to solve with more stupidity which causes even more trouble and so forth.

Consistency is a concept which doesn't seem to be familiar to Stone as well. Before the said encounter Harry aproached one of the aliens. It didn't shoot at him but instead pointed some kind of energy beam at him which made him able to "see" some kind of a message (that the red dwarf is about to go nova, that is). However, Stone abandons the episode completely during the following chapters. On several occassions Harry reasons why the aliens don't communicate with him. Though they did, but Stone the author, just forgot. Utter madness!

Another problem figure is the Fagen character, the commander of the mission. He seems to be manipulative, keeps secrets about the mission and lies on serveral occassions. At the very beginning of the book there's a sequence where Fagen was previously at the planet they visit later again. Most of his crew got killed by aliens and one crewman (a women, I'll come to that later) wants to screw him up (for the money. again!), so he kills her. His motive seems to be that he's annoyed by corporation rules and money making, or so he says. Only on the first couple of pages you can clearly see, that almost all of the first crew are psychopaths. I don't understand how a profit oriented space corporation could send such dump loosers out into the universe to explore it. And it's not better with the current crew as well. The point is, Fagen redirected the Maghellan (their ship) to the said planet again. But we never learn for what reason, at least not in the first half. Perhaps that will resolved later, I hope.

Then there are the women. Psychos. All of them but one. The latter is beautiful and has a lovely attitude which seems to be her only talent. Also she's white. Any other female character is either dump, corrupt, egocentric or all of it combined. This goes far beyond simple sexism, it's insulting for any sentient being - female or male alike. Mad, irrational people everywhere. I'd say you could remove circa fifty per cent of the book just by making the characters reasonable.

But physics and technology are the worst of it. It starts with a wormhole they discovered sometime earlier which can be used to travel the galaxy. There's an entry interstice in our solar system and depending on your entry speed you will drop out at some specific point somewhere else, so that practically every point in the galaxy (or universe?) could be reached. There's no explanation why that would be so. It's just so. Because. You know. And then there's the way back home. Not explained at all.

Stone writes about a red dwarf which is about to go nova. Except that red dwarfs don't do that. The crew wears spacesuits, walk the hot planet surface in it but sweat heavily. Because, you know, in 2200 spacesuits don't have environmental systems built in. Oh, and they cannot communicate with the ship above in orbit, since they all left the shuttle. The suits have radio capabilities but totally obviously they cannot use the shuttle as a relay to talk with orbit. Oh - and an explosion in space causes a shock wave. Ridiculous.

The shuttle hangar (side note: Stone writes it as "hanger", for whatever reason) has a decontamination feature which will be used regularly when the shuttle comes on board of the space ship after a planetary visit. However, the people inside just went outside on the planet, helmets open. So, they get contamined by alien microbes and they contamined the alien world with earth's microbes - and don't give a shit about it. But they clean the outside of the shuttle after it flew through the vacuum. Another aspect of the shuttle is also interesting: there's some defect and it turns out that some pipe leaks hydraulic fluids. An engineer repairs it later. The interesting thing is, he does it while laying below the shuttle. Since hydraulic pipes are naturally mounted UNDER a space shuttle, which means at the OUTSIDE if it. And then they wonder why it gets off when entering the atmosphere? Huh?!

Another character - the "computer genius" as Stone tells us on every possible occassion - uses a CD player. I abandoned my CD player about 10 years ago. That is, before the book had even been written. WTF? And the guy only hooks into computers. Not into the net. In fact, there's no net in the book. Which have been written while the internet is an old hat these days. You don't even have to imagine such things, just look out into our very own world. It looks as if the book have been written in the 1950s.

In summary, I'd assume Stone tries hard to deliver a good story but has no idea of science. Or science fiction. He probably never read a scify story. You'd already know the most basics just by reading some piece of Clarke or Asimov. And he seems to have no affinity to the internet as well. Would it really be too much just googling "super nova" and reading some sentences about it on wikipedia? He makes the impression on me to be the one who wrote the Prometheus script. Don't get it wrong, everyone has to start somewhere so has Stone. In some reviews I read that it get's better in the following books, so there's hope.

However, I like the story anyway! Don't ask me why :) And I'm eager to see how it develops. That's probably the craziest thing about the book. It doesn't make any sense in most parts, the party is run by a pack of fools, but it's kinda funny and exciting. Didn't have such a combination ever...

Update 2014-07-18:

I’m done with the book, in both senses - I’m not going to read the other two of the trilogy. It’s just too lame. Can’t sustain it any longer. I found even more bullshit in the remainder. For one it’s the problem with free fall Stonce seems to have. You see, in free fall there’s no gravity at work so you don’t weight anything in such an environment. You move by floating around, you can’t fall down, fluids form spheres flying around if exposed to force, things stay right in the air where you stick them, and the likes.</p>

Not so in Stones world. There, an injured one moves around the ship to search for an alien together with a crewmember. Sometimes they (correctly) float around, sometimes they "stand" or "walk". Then, after some time he complains that his foot hurts and he needs to get back to his bunk in order to lie down and rest. I'm not sure why his foot hurts, obviously from "walking" around a longer time in the ship, under free fall conditions. You would assume, that free fall would be one of the best possible conditions if your foot hurts. Since - you know - you don't weight anything, which relieves the foot the best way possible. But as it is, Stone doesn't have any clue about such details. Oh, and the same character engages in a foot bath earlier.

Other crew members are on board of the alien craft, there's free fall as well. At least at some point Stone writes it. But the aliens walk around all the time, they don't float. And the crew sometimes floats but sometimes crawls or walks. There's a tunnel which leads "downward" (how do you know in free fall on board of an alien ship where that "down" might be?), two of them fall down, one onto the other. In fucking free fall. Crackbrained, that is.

I already mentioned the women who wants to leave the system no matter what, even when the majority of the crew is not on board. So they've got an alien on board and a rare event happens: they shut down all the hatches. Wow, Mr. Stone, there you have it: 1 point out of 100 negatives! While the others look out for the alien, said women waits. Finally the alien catches both of them and kills them. The women doesn't hear anything from them for a long time, so she decides to open all the hatches. Because reasons. I don't know how many times I face palmed during the last chapters.

Stone doesn't know about vacuum either. Said alien which boards the human vessel, "leaves the ship silently". That is a citation. SILENTLY. Honestly, Mr. Stone, were you stoned when you wrote that utter crap?!
Haha, one last piece: they missed one crew on the planet (Harry) but he managed to leave the surface anyway on board of the alien shuttle. The shuttle goes to the alien ship from where Harry flees and comes aboard the Maghellan again. Guess what they say to him on first sight? "How are you doing?". LOL.

So, I wont buy the other two books, it just hurts too much. Yes, I'd like to know how it continues, since the plot as it is, isn't bad at all. But as a detail loving nerd I can't stand it any longer. Sorry.

14 July 2014 | #literatur


New shell gimmicks

So, I decided to streamline my shell config the other day. The very first I did, was to write an awk replacement in perl. Sounds a little senceless, but sometimes I need some more power inside an awk command and sometimes I just want to save typing. This is how it looks like, when used:

# awk version:
ps | grep sleep | grep -v grep | awk '{print $1}' | xargs kill
# pwk version:
ps | grep sleep | grep -v grep | pwk 1 | xargs kill

This is the simple variant, which just saves typing, pretty handy. The other variant is more perlish and at first looks like the original awk syntax. Hover, you can add almost any kind of perl code to it:

ps | pwk 'if($5 =~ /^python$/) { $t=`fetch -o - "http://$8/"`; if($t =~ /<title>(.+?)<\/title/) { print "$8: $1"} }'

Here's the shell function, just put it into your .bashrc:

pwk () {
    if test -z "$*"; then
        echo "Perl awk. Usage:"
        echo "Perlish: pawk [-F/regex/] [-Mmodule] <perl code>"
        echo " Simple: pawk <1,2,n | 1..n>"
        echo "Perlish helpers:"
        echo "  p() - print field[s], eg: p(\$1,\$4,\$7)"
        echo "  d() - dump variables, without param, dump all"
        echo "  e() - exec code on all fields, eg: e('s/foo/bar/')" 
        echo "Default loaded modules: Data::Dumper, IO::All"
        echo "Enable \$PWKDEBUG for debugging"
        echo "Simple mode has no helpers or anything else"
        # determin pwk mode
        if echo "$*" | egrep '^[0-9,\.]*$' > /dev/null 2>&1; then
            # simple mode
            code=`echo "$*" | perl -pe 's/([0-9]+?)/\$x=\$1-1;\$x/ge'`      
            perl -lane "print join(' ', @F[$code]);"
            # perl mode
            # prepare some handy subs
            uselib="use lib qw(.);"
            subprint="sub p{print \"@_\";};"
            subsed='sub e{$r=shift; foreach (@F) { eval $r; }};'
            subdump='sub d {$x=shift||{_=>$_,S=>\@F}; print Dumper($x);};'
            begin=";  BEGIN { $uselib $stdsplit $subprint $subdump $subsed}; "
            # extract the code and eventual perl parameters, if any
            for arg in "$@"; do
                args="$args $last"
            # fix perl -F /reg/ bug, complains about file /reg/ not found,
            # so remove the space after -F
            args=`echo "$args" | sed -e 's/-F /-F/' -e 's/-M /-M/'`
            # convert $1..n to $F[0..n]
            code=`echo "$code" | perl -pe 's/\\\$([0-9]+?)/\$x=\$1-1;"\\\$F[\$x]"/ge'`
            # rumble
            if perl -MIO::All -e0 > /dev/null 2>&1; then
                defaultmodules="$defaultmodules -MIO::All"
            if test -n "$PWKDEBUG"; then
                set -x
            perl $defaultmodules $args -lane "$code$begin"
            if test -n "$PWKDEBUG"; then
                set +x

Another new shell function is extr, which unpacks any kind of archive. In contrast to its sisters out there (there are a couple of generic unpack shell funcs to be found on the net), it takes much more care about what it does. Error checking, you know. And it looks inside the archive to check if it extracts into its own directory, which is not always the case and very annoying. In such instances it generates a directoryname from the archivename and extracts it to there. Usage is simple: extr archivefile. Here's the function:

extr () {
    act() {
        echo "$@"
    n2dir() {
        dir=`echo "$tarball" | perl -pne "s/.$suffix//i"`
        dir=`basename "$dir"`
        echo "$dir"
    if test -n "$tarball"; then
        if test -e "$tarball"; then
            if echo "$tarball" | grep -Ei '(.tar|.jar|.tgz|.tar.gz|.tar.Z|.tar.bz2|tbz)$' > /dev/null 2>&1; then
                # tarball
                if echo "$tarball" | grep -E '.(tar|jar)$' > /dev/null 2>&1; then
                    # plain old tarball
                elif echo "$tarball" | grep -E '(bz2|tbz)$' > /dev/null 2>&1; then
                elif echo "$tarball" | grep -E 'Z$' > /dev/null 2>&1; then

                if ! tar ${extr}tf "$tarball" | cut -d/ -f1 | sort -u | wc -l
                    | egrep ' 1$' > /dev/null 2>&1; then
                    # does not extract into own directory
                    dir=`n2dir "$tarball" "(tar.gz|tgz|tar.bz2|tbz|tar|jar|tar.z)"`
                    mkdir -p $dir
                    extr="-C $dir -${extr}"
                act tar ${extr}vxf $tarball
            elif echo $tarball | grep -Ei '.zip$' > /dev/null 2>&1; then
                # zip file
                if unzip -l "$tarball" | grep [0-9] | awk '{print $4}' | cut -d/ -f1 | sort -u \
                    | wc -l | egrep ' 1$' /dev/null 2>&1; then
                    # does not extract into own directory
                    dir=`n2dir "$tarball" zip`
                    act mkdir -p $dir
                    opt="-d $dir"
                act unzip ${opt} $tarball
            elif echo "$tarball" | grep -Ei '.rar$' > /dev/null 2>&1; then
                if ! unrar vt "$tarball" | tail -5 | grep '.D...' > /dev/null 2>&1; then
                    # does not extract into own directory
                    dir=`n2dir "$tarball" rar`
                    act mkdir -p "$dir"
                    (cd "$dir"; act unrar x -e $tarball)
                    act unrar x $tarball
            elif echo "$tarball" | grep -Ei '.gz$' > /dev/null 2>&1; then
                # pure gzip file
                act gunzip "$tarball"
            echo "$tarball does not exist!"
        echo "Usage: untar <tarball>"

And finally an updated version of my h function, which can be used for dns resolving. Usage is pretty simple:

% h
; dig +nocmd +noall +answer         346     IN      A

% h
; dig -x +short

% h mx
; dig +nocmd +noall +answer mx         1800    IN      MX      5         1800    IN      MX      5         1800    IN      MX      5

It uses dig to do the work, or host if dig cannot be found. The source:

h () {
    if type dig > /dev/null 2>&1; then
        opt="+nocmd +noall +answer"
        if echo "$args" | egrep '^[0-9\.:]*$' > /dev/null 2>&1; then
            # ip address
            cmd="dig -x $* +short"
            # hostname
            cmd="dig +nocmd +noall +answer $*"
        echo "; $cmd"
        # no dig installed, use host instead
        cmd="host $debug"
        if test -z "$host"; then
            echo "Usage: h <host> [<querytype>]"
            if test -n "$2"; then
            if test -n "$debug"; then
                set -x
            case $type in
                    $cmd -l $host
                    cmd=`echo $cmd | sed 's/\-d//'`
                    $cmd -d -t any $host | grep -v ^\; | grep -v "^rcode ="
                    $cmd -t $type $host
                    echo "*** unsupported query type: $type!"
                    echo "*** allowed: mx, a, ns, any, *, soa, cname, ptr"
            if test -n "$debug"; then
                set +x

03 July 2014 | #source


subst update (1.1.3)

So, after a couple of idle years I made an update to my subst script. Although I use it everyday there were still some glitches here and there. For one, I just could not rename files with spaces in them. Very annoying. Also it was unflexible in that I could not use additional perlmodules when using /e. STDIN was not supported among other minor stuff.

So, the new version fixes all this, see the link above. Download, rename it (remove the .txt extension) and put it into your bin directory. Usage:

Usage: subst  [-M <perl module>] [-t] -r 's/old/new/<flags>' [ -r '...', ...] [<file> ...     | /regex/]
       subst  [-M <perl module>] [-t] -m 's/old/new/<flags>' [ -m '...', ...] [<file|dir> ... | /regex/]

 -r        replace contents of file(s)
 -m        rename file(s)
 -M        load additional perl module to enhance /e functionality.
 -t        test mode, do not overwrite file(s)

 - replace "tom" with "mac" in all *.txt files:
   subst -r 's/tom/mac/g' *.txt

 - rename all jpg files containing whitespaces:
   subst -m 's/ /_/g' '/.jpg/'

 - decode base64 encoded contents
   subst -M MIME::Base64 -r 's/([a-zA-Z0-9]*)$/decode_base64($1)/gem' somefile

 - turn every uri into a link
   subst -M "Regexp::Common qw /URI/" -r 's#($RE{URI}{HTTP})#<a href="$a">link</a>#g' somefile

If <file> is -, STDIN will be used as input file, results will be printed
to STDOUT. -t does not apply for STDIN input.

Substitution regex must be perlish. See 'perldoc perlre' for details.

Version: 1.1.3. Copyright (c) 2002-2014 - T.v.Dein <tom AT linden DOT at>

So, in order to remove spaces of filenames, I can now just issue:

subst -m 's/ /_/g' '/\.mp3$/'

As you can see, instead of giving a shell wildcard as last argument, I provide a regex, which will be resolved by the script itself from the current directory. Bam!

01 July 2014 | #source