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}
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.
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.
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.
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.
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.
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.
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:
- Email processing
- Spam filter scripts
- The setup of my financial overview
- Make files
- m4 macros
- and much more....