jeroen.se
by jnieuwen
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
using nrpe to check a network behind NAT
29 May 2007 17:24 - This weekend I had the problem that I had to check several hosts on a network behind NAT with nagios. One solution would be to add portforwardings on the NAT firewall for each host and use check_nrpe with different port settings from the nagios machine. This is of course a maintenance nightmare.
The solution that I choose was therefor a little different. I installed nrpe server and the nrpe plugins on all hosts. Then a portforwarding to port 5666 of one host (irobot) was added in the firewall. In the nrpe config of irobot I added the checks for irobot and checks for the other hosts by adding lines like these to the nrpe.cfg of irobot:
cammand[vacdepot_fs_root]=/usr/lib/nagios/plugins/check_nrpe -H vacdepot -c check_fs_root
In the nrpe.cfg of vacdepot check_fs_root is defined of course.
So I am using nested nrpe calls to get the data I want. The advantage being that I do not have to have a portforwaring for every host I want to monitor behind the NAT firewall.
0 comments
string replacements in bash
28 May 2007 12:34 - Sometimes you will find that in bash you have to do a substitution in the value of a variable. i.e. in my blogging scripts I have the filename in the variable POSTFILE and for this posting POSTFILE has the value of 2007-05-28-12-34_string_replacements_in_bash.m4.
But when I have to generate a link to the post it should end in .php instead of .m4. The naive approach would be to do something like:
echo $POSTFILE | sed "s/\.m4$/\.php/"
Bash however has a more elegant solution for this:
echo ${POSTFILE/%\.m4/.php}
Where % means to match at the end of the POSTFILE variable. More information about the syntax can be found in the bash man page in the Parameter Expansion section.
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
RSS feed added
25 May 2007 17:48 - After about 15 minutes of playing around I have the script to generate RSS feeds for my blog ready. Although the total interaction of how my blogging software works is to complex to explain in a short blog article.
0 comments
Posting to my blog with makepost.sh
25 May 2007 07:35 - Yesterday I wrote about my blogging software which consists of a few shell scripts and some m4 macros. Today I will show you one of the most important scripts from this blogging toolkit: makepost.sh.
#! /usr/bin/env bash
set -x
ITEM="$*"
FILEINFO=$(echo $ITEM | tr " " "_")
FILENAME=$(date +"%Y-%m-%d-%H-%M_$FILEINFO.m4")
sed "s/_TITLE_/$ITEM/" entry.m4 > $FILENAME
svn add $FILENAME
svn propset svn:keywords Id $FILENAME
vim $FILENAME
What it does is simple. It generates the filename to use for this blog post`,' based on the date`,' time and title. Copies the posting template to the blog post file`,' while setting the title correct. It adds the post to the subversion repos and starts vim to edit the file. After that I only have to start writing.
0 comments
My blogging software
24 May 2007 22:32 - I use my own blogging software to maintain my blog. Writing it took approximately 1.5 hours and it consist of 40 lines of bash shell scripts and 456 lines of m4 macros. But it is not finished yet. The main thing lacking is the updating of the jeroen.se rss feed. So that will be one of the projects for the comming week.
Although it lacks some features of the most blogs``,'' i.e. my blogs software does not support comments``,'' its simple design makes it simple to write blog posts on my palm treo 650.
0 comments
The start of the blog
24 May 2007 22:21 - Well there it is. My own blog. Its going to be about the things I automate with shell and other scripts. So you can expect posts about the scripts I use for:
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)