jeroen.se
by jnieuwen
perl script to make adding reverse dns entries for ipv6 easier
17 November 2010 17:00 - I am doing a lot more then before with IPv6 lately. And one of the things I ran into was adding reverse IPv6 entries to bind. i.e. 2001:980:5e60:1:f2b5:796f:fe12:9389 should have a reverse dns entry in the 0.6.e.5.0.8.9.0.1.0.0.2.ip6.arpa. zone. To be more precise:
9.8.3.9.2.1.e.f.f.6.9.7.5.b.2.f.1.0.0.0 PTR test.ipv6.jeroen.se.
I made a simple perl script to reverse the IPv6 IP address for me: ipv6reverse.pl
Usage:
ipv6reverse.pl 2001:980:5e60:1:f2b5:796f:fe12:9389
Output:
9.8.3.9.2.1.e.f.f.6.9.7.5.b.2.f.1.0.0.0.0.6.e.5.0.8.9.0.1.0.0.2
0 comments
fetching voicememos from my nokia 6600i
15 June 2010 20:04 - Finally some time to finish this blog post. I already wanted to write it in June. It is about how I integrated voice memos in my GTD workflow.
When I do not have access to pen, paper or a computer I capture most ideas and todo items in the voice memo recorder of my nokia 6600i. To make sure these voice memos are processed I use some scripting on my Linux server at home and a bluetooth dongle to automatically fetch these memos from my phone to the inbox folder on my computer.
First I had to allow my Linux server (Debian Sarge) to connect to my Nokia:
jnieuwen@sigrun:~$ hcitool scan
Scanning ...
XX:XX:XX:XX:XX:XX jnieuwen 6600i
cd /usr/share/doc/bluez-utils/examples/
make
./passkey-agent --default "1234"
obexftp -b XX:XX:XX:XX:XX:XX -l
Then I daily run to following script from crontab on my linux server.
#! /bin/bash

PATH=/home/jnieuwen/bin:/usr/local/bin:/usr/bin:/bin:/usr/games
export PATH

cd $HOME/inbox || exit 1

DATUM=$(date +"%s")

# TODO Get all the file names
obexftp -b XX:XX:XX:XX:XX:XX -l "Opnamen" | grep "<file name=" | sed -e 's/.*name="//' -e 's/".*//' | while read FILENAME
do
    echo ${FILENAME}
    obexftp -b XX:XX:XX:XX:XX:XX -g "Opnamen/$FILENAME"
    obexftp -b XX:XX:XX:XX:XX:XX -k "Opnamen/$FILENAME"
    mv $FILENAME ${FILENAME/.amr/.${DATUM}.amr}
done

exit 0

0 comments
some tricks I use when using zsh and screen
11 February 2009 18:46 - If you are like me administrating lots of unix servers where you have to do different tasks at different servers simultaneously then you can easily lose track of which screen window is doing what on your laptop. My solution for this in the zsh shell is using the following in my .zshrc:
preexec()
{
    if echo ${TERMCAP} | grep screen > /dev/null
    then
        screen -X title ${1}
    fi
}

precmd()
{
    if echo ${TERMCAP} | grep screen > /dev/null
    then
        screen -X title $(echo $PWD | sed "s#$HOME#~#")
    fi
}
This sets the title of a window where a command is running to the name of the command being run. When no command is running it sets it to the current working directory. The advantage is that I no longer have to set the titles manually. The disadvantage is that the titles can get very long. Therefor I have in my .screenrc the following line:
bind l windowlist
Which allows me to quickly get the window list with ^Al.
0 comments
avoiding mistakes with numbering
04 February 2009 08:09 - Last week I thought a little about naming volumegroups on SANs, logical volumes, hosts and (micro)SD cards. They all have one thing in common, if you have a lot of them you hardly can avoid numbering them. The only problem with this is of course small typos that can lead to disasters. Fortunately there are of course solutions for this.
After some thinking I thought about using checksums in the numbering, which makes it harder to create a disaster with just one typo. The best scheme I could find to work for this was using the ISBN numbering scheme.
So i.e. I now number my (micro)SD cards as follows: As you probably can see the first number is the checksum digit. A number is valid if and only if the checksum digit + 2 times the second number + 3 times the third number + 4 times the fourth number ... modulo 11 = 0. Note that the checksum digit can also be X to indicate a value of 10.
If you look at the jni-60001 number. The checksum is 6. And the 1 is multiplied by 5. Summarized this makes 11, which modulo 11 is of course 0. So this is a correct number. But what if we make a typo i.e.:
Of course I created a script for this that does all the hard work. It can be found here.
0 comments
new version of jnitodo available
28 January 2009 18:18 - The newest version of jnitodo is available from here.
New in this version is the following:
  1. The f command as shortcut for a wait ...
  2. You can quickly set the date of an item to the current date with the n command.
  3. Number of items marked in progress and today now visible in the status bar.
  4. You can add autoqueue=1 to the config file to automatically read the queue before each command.
  5. You can clear the history buffer with the ch command.
  6. The t b d and u commands can now handle more than 1 item number at once.
  7. When adding items you can use + as shortcut for the current context.
  8. Autocompletion of contexts for the a c and l commands
Check out the CHANGES file for all updates.
0 comments
jniatd beta released
19 January 2009 08:52 - The first public beta of my jniatd script is available. jniatd is a perl based proof of concept for a class based at daemon. Which means that a job will run only when the specified time has passed and the class it belongs to evaluates to true.
More info on the jniatd page.
0 comments
a small perl script to check if a file is in dos format
18 November 2008 08:12 - Last week I made a small perl script to check if a file is in dos format. You can download it here.
0 comments
irc hilights to a rss feed
11 November 2008 16:50 - 2 weeks ago I wrote about the dblogger script I use to log irc conversations to a database. One of the things I use this for is to generate a rss feed of hilights I have on IRC. A sample php script todo this can be found here.
0 comments
dblogger a irssi script to log to mysql
28 October 2008 19:06 - dblogger.pl is a simple perl script for irssi. dblogger.pl logs all public messages and actions to a mysql database. The sql to create the needed table in the database can be found here.
Now we have database logging the fun can start. (To be continued...)
0 comments
setting your location from the command line on Mac OS X
07 October 2008 19:07 - I am often working on the commandline and then it is some extra work to change the location by using the System Preferences. So I added the following function definition to my .zshrc
setloc() { scselect $(scselect 2>&1 | grep $1 | awk '{print $1}') }
After that I can change my location by using:
setloc vanaheim or setloc ilmatar
1 comments
version 2396 of jnitodo released
05 October 2008 13:24 - Today version 2396 of jnitodo is released. This release features a lot of small improvements. Including:
Download version 2396 from the jnitodo page.
0 comments
jnitodo a console based todo list manager
25 August 2008 17:46 - Since a few weeks I use the jnitodo todo list manager for managing my todo list. jnitodo was written by myself, so it matches my requirements quite well and it might match yours!
Features
jnitodo has some nice features. First of all it is console based and written in perl. I tested it on Mac OSX and FreeBSD. Secondly it has support for GTD like contexts. Using contexts is in fact obligatory. It should be noted that wait is a special context which will ask for who or what you are waiting.
Queue support
The feature I am most proud of however is its queueing support. Forget about manually adding all tasks. Think procmail. Think cron. Think atd. Think nagios. Think bluetooth. Think sftp. The sky is the limit.
How does the queue support work? In the config file of jnitodo you must define a queue directory. In this directory you can place files with lines in one of the following formats:
context:todo
wait:who:waitingfor
i.e. a line in a queue file could be:
train:write blog post about jnitodo
wait:Jeroen van Nieuwenhuizen:release of a new jnitodo version
Note that the queue function will not add duplicate entries to your existing todo list.
Usage
The usage of jnitodo is quite simple. You need to create a config file with lines like:
todofile=/Users/jnieuwen/files/t/todos/todo.txt
queuedir=/Users/jnieuwen/queue/jnitodo
Of course you need to adjust the paths to match your situation. Then you have to make sure you have an empty todofile. So create it with touch /Users/jnieuwen/files/t/todos/todo.txt where of course you need to substitute /Users/jnieuwen/files/t/todos/todo.txt for your value of the todofile parameter in the config file.
Now you can run jnitodo with the command:
jnitodo.pl /path/to/config_file
For usage information you can press the ? key to get the help.
Download
jnitodo can be downloaded here. It should be noted that there is room for improvement in jnitodo.
Questions? Ideas? Send an email or drop them in the comments.
0 comments
using the gps of the n810 to get cycling statistics
31 March 2008 08:55 - Since a few weeks I have a nokia n810. Mainly because of the ability to login via ssh on servers I manage. This allows me leave my laptop at home when using my recumbent bike, which saves around 1.5 KG of luggage. But it also allows me to save my track and speed info by using the built-in GPS module.
Saving the track in gpx format is quite easy using maemo-mapper. But maemo-mapper does not save the speed information, hence I needed something else. Fortunately the n810 has gpsd running when the gps is in use and also has perl installed. So my problem was reduced to making a perl script that talks to gpsd.
The first script I needed was a script to save all the information from the gpsd daemon. The usage is quite simple. Start maemo-mapper and after that run the perl script. This creates a simple log file.
After returning from your trip you just kill the perl script and copy the logfile to your desktop machine. Then you run the plot script:
speedplot.pl speed.log output.png
And you have a graph of your speed during the ride in png format. The speed is averaged over all the measurements of the last minute, because the speed of a bike is to low to get an accurate speed measurement from just one sample. An example png can be found here.
Taking the n810 with me is quite easy, I put it in my topbag on the back of the bike. In the bag it still can get a gps fix and it is protected against rain. I am still thinking how to mount it on the bike to be able to use it for following a predefined route.
What is a problem though is that I do not get any good altitude samples. I have to look into that to see if I can fix that and be able to make a altitude graph.
1 comments
using shell scripts to summarize email
20 February 2008 08:04 - I get a lot of email and have no intention of reading all email I get. Hence I filter all my email using procmail. I.e. I put a lot of non urgent email directly in a holding queue which is only put in my inbox once a week. But this still presents me with another problem: Once a week my inbox is extremely full with email. Therefor I looked at ways to summarize my email.
First I had to decide which email I can summarize. The easiest candidates are emails I get very often with only a few lines I am interested in, i.e. the subject or a few lines from the body. For this simple scripts, like the one linked to below, can be created. I have several of these scripts to summarize mails from mailing-lists etc. These scripts are run over the holding queue before putting all email from the holding queue into my inbox. Using these scripts reduces the amount of email in my inbox with over a hundred messages a week.
A sample shell script I use for summarizing the buqtraq mailing-list can be found here.
0 comments
summarize irc topics from emails
08 January 2008 16:52 - I am in a lot of irc channels and in each of these channels the topic of the channel can change a few times per day. Of course I do not want to check the topic too often for changes. But on the other hand I also do not want to mis meeting or party announcements. Some googling gave me a irssi plugin to send an email per topic change. So far so good. But that meant that I had to read a lot of emails extra. Which means it still cost more time than needed to follow the changes in the topics.
Hence time to update my procmail filter to send those emails to a separate Maildir and create a script to summarize these emails: topic2single.pl. It reads mailfiles from standard input and summarizes all topic changes from these emails. I use the script with a rule like: find /home/jnieuwen/Maildir/.topic/new | topic2single.pl | sort | uniq and pipe the result of this to the mail command.
As a result of this I only have to read one email with topic changes a day. If your topic change emails have the same format: <nick> changed the topic of <channel> to: <topic> on a single line in the mail file then the script may work for you too.
0 comments
number of msn and other im users in the statusbar
30 November 2007 07:59 - After creating a script to put the number of users in each IRC channel I am in into a file for rddtool processing`,' I thought it would be nice to have the number of online users in my bitlbee channel in the statusbar. Hence I created the following script.
To use the script`,' copy it to the .irssi/scripts directory and load the script. Then do something like /statusbar add jeroen_se_bitlbee
0 comments
running sudo on multiple host or a great way to shoot your self in the foot
22 November 2007 21:04 - Sometimes you need to execute a command on a lots of hosts on which you only have sudo access. This is easy when the NOPASSWD option is set for you in the sudoers file. However if this is not the case you run the risk of typing your password to often. So yesterday I created sudoatall.sh. A simple shell script to solve this problem. The usage is something like sudoatall.sh <file with hostnames> <what ever you want to execute>
There are however 2 catches. First the script has your sudo password assigned to a variable. Secondly it is of course a great script to break all your hosts at once.
0 comments
scheduling a not cron safe job more then once
19 November 2007 18:10 - Last week I ran in to the problem that my svntag.sh script should run on the first of every month. Unfortunately my svntag.sh script misses all kind of PATH info so it will probably not run as a cronjob without modifications.
Being to lazy to check and fix the possible problems while running from cron`,' I came up with:
for i in {0..24}
do
echo svntag.sh | at -t $(date -j -v+${i}m 200712010407 +%Y%m%d%H%M)
done
Which works when using the zsh shell on FreeBSD.
0 comments
counting the users in your irc channels
14 November 2007 08:31 - Yesterday someone in an irc channel I am in was trying to graph the current number of users in the irc channels he is in with Cacti. His problem was quite simple: How do I get the number of users out of my irssi? My default statement in those cases is: "Just script it. It can not be that hard."
And fortunately it is not. Although I was not able to complete the script in the estimated 15 minutes (Blame the GPRS coverage between apeldoorn and amersfoort)`,' I did fix the script in 26 minutes. You can download the script here.
The usage is quite simple: Just load the script in irssi and set the output file to something usefull with /set usercountlog_file /where/you/want/your/file. And every minute or so the file is updated with the current number of users. The format of the file should be self explanatory.
0 comments
a blog to news items script
11 November 2007 15:18 - Today I noticed that the news items sections of my webpage are mostly outdated or incomplete. Hence I created a script to update the news section from the blog postings I make.
0 comments
can you make a command that
26 October 2007 20:53 - The question: Can you make a command line that finds the string abcdefg in all files modified between 2007-09-23 07:00 and 2007-09-24 01:00?
And of course I can:
find . -daystart -mmin -$(echo $(date +"%s" -d"$(date +"%Y-%m-%d 0:00)") $(date +"%s" -d"2007-09-23 7:00") - 60 / 1440 + p | dc) -mmin +$(echo $(date +"%s" -d"$(date +"%Y-%m-%d 0:00)") $(date +"%s" -d"2007-09-24 01:00") - 60 / 1440 + p | dc) -exec grep -H abcdefg {} \;
0 comments
using nagios to monitor your todolist
11 June 2007 17:11 - Last week I decided to monitor my todolist with nagios. This mainly because I have the tendency to delay some todos for a very very long time. To be able to do this I had to include the date of entry of a todo item to my todo list format. The original format of my todo list can be found here. I changed the format to
- <context>:<year>-<month>-<day>: <description>.
I also had to change the addfolds.pl filter to be able to ignore the date when sorting and removing duplicates. The new addfolds.pl can be found here.
For security reasons I do not want the nagios user to be able to read my todo list. Hence I use check_jnieuwen.py to read the nagios status information from a file. Which uses a simple fileformat which is probably easy to understand when looking at the code.
The next step is of course getting the status information in the status file. This is accomplished with the check_todo_age.py script. This script is run hourly from cron.
0 comments
irc hilights displayed in the zsh shell
07 June 2007 07:51 - zsh has another nice feature I use to display the latest hilights on irc. The zsh option I use for this is the periodic function and the PERIOD environment variable. First off all I have set PERIOD to 60 in my ~/.zshrc config file. This ensures that the periodic function is executed before a new prompt if at least 60 seconds have passed.
The periodic function is defined as:
function periodic() {
diff $HOME/.periodic/last_hilight $HOME/.periodic/last_hilight.old | grep "^<" | cut -f2- -d: | sed -e "s/:/ /" -e "s/^/IRC: /" && cp $HOME/.periodic/last_hilight $HOM E/.periodic/last_hilight.old
}
Which means that it compares the $HOME/.periodic/last_hilight file with the $HOME/.periodic/last_hiligt.old file and displays the difference.
You might wonder how the last hilight from irc now comes in the $HOME/.periodic/last_hilight file. This is accomplished by an irssi plugin I extended. More on this plugin later because I still have to document this extension.
0 comments
only match on specified field in awk
31 May 2007 07:50 - Today I discovered that you can let an regular expression in awk only match to a specified field. i.e. normally I would try to do something like:
/^[^ ]?.*2.*[ ]/ { print $2 }
to check if the second field contains a 2 and then print it. But awk has the ~ operator which makes this much easier:
$2 ~ /2/ {print $2}
0 comments
Setting your ssh public keys on a host
26 May 2007 23:38 - One of the things I often have to do when arriving at a new customer is adding my public keys on the hosts I have to work on. To simplify this process I use the following script:
`
#! /bin/sh
# Installs the jnieuwen ssh keys on an account.

mkdir $HOME/.ssh || exit 1
chmod u+rwx $HOME/.ssh || exit 1

cat $0 | sed "1,/^CUTFROMHERE/d" >> $HOME/.ssh/authorized_keys || exit 1

chmod og-rw $HOME/.ssh/* || exit 1
chmod og-rwx $HOME/.ssh || exit 1

exit 0
CUTFROMHERE
ssh-rsa AAAAB3Nz5[........]dtM0S4fdd
ssh-rsa AAAAB3Nza[........]A5F7lnhdD'
So I just copy this script with scp to the host and then execute:
ssh <host> sh <script>
To use it just replace the SSH public keys after the CUTFROMHERE rule with your own.
0 comments
Categories
Cycling (2)
Gadgets (3)
IPv6 (1)
Misc (27)
Scripting (25)
Travel (7)
Unix (24)
Archive
January 2013 (1)
October 2012 (1)
September 2012 (1)
May 2012 (1)
February 2012 (1)
January 2012 (1)
January 2011 (1)
November 2010 (1)
June 2010 (1)
April 2010 (2)
January 2010 (1)
December 2009 (1)
November 2009 (2)
May 2009 (1)
April 2009 (1)
March 2009 (1)
February 2009 (7)
January 2009 (3)
December 2008 (1)
November 2008 (4)
October 2008 (5)
September 2008 (1)
August 2008 (3)
July 2008 (2)
June 2008 (2)
May 2008 (3)
April 2008 (1)
March 2008 (1)
February 2008 (1)
January 2008 (4)
December 2007 (1)
November 2007 (7)
October 2007 (4)
September 2007 (1)
August 2007 (2)
June 2007 (6)
May 2007 (8)