Tag Archives: shell

icinga logo

Icinga2 email via ssmtp

I have been playing around with Icinga2 for some monitoring at home. I wanted to monitor a few of my external services. Since my email is one (or the primary) of them I needed alert notifications to be sent via something else. So I setup ssmtp and have email sent through a gmail account.

Make sure to enable the account to be accessible by less secure methods for this to work. If anyone comes across a way to not have to enable that, please let me know. Continue reading


Favourite command of the day – kodi-send

This is an update of a post I wrote a couple of years ago about triggering an update of OpenELECs media library since the XBMC project has since changed its name to Kodi.

For the videos now use:
OpenELEC:~ # kodi-send --action="KODI.updatelibrary(video)"

Also worth noting is that nowadays root seems to be the default login.


Accessing the OS X clipbord in VIM

I’m a vi kind of guy and uses various flavors of it a lot. One thing that took me all too long before I got around to set up was proper access to the OS X clipboard from vim.

There are all kinds of howtos on this out there, so I will just cut to the chase but one thing to point out is that depending on compile options you might have good access to the clipboard already. One way to check is by running :echo has('clipboard') in vim. If it returns 0, you don’t have it compiled with the clipboard. This is the case for the all the vim’s I have checked that ships with OS X. If yours is different please leave a comment with some details about OS X and vim versions.

In your .vimrc add the following lines
" paste on new line (after current) from OS X clipboard
map pbp o<Esc>:.!pbpaste<CR><CR>

" copy visual selection to OS X clipboard
vmap pbc :w !pbcopy<CR>

It’s probably obvious to anyone who has used vi what these lines do, but they map pbp to run the external commands pbpaste (paste from OS X clipboard) and the visual selection alias pbc to run pbcopy.

Pbpaste and pbcopy are available by default as a part of OS X.


Quick script to check if a domain is about to expire

A couple of nights ago I threw together a quick script to be able to do some automatic checks to see if my domains are expiring. The script is full of ugly code but it gets the job done and I can now loop through a list of domains. Example of usage below. Continue reading


Favourite command of the day – xbmc-send

Using xbmc-send one can remotely via SSH trigger a rescan of the media library. For example the videos like here below.
apathy:~ $ xbmc-send --action="XBMC.updatelibrary(video)"
Sending action: XBMC.updatelibrary(video)

The xbmc-send command can be used for a lot of things and is well worth looking further into.
This works fine for me on OpenELEC version 3.0.6.


Updates to a couple of my FreeNAS scripts

I have updated a couple of the scripts mentioned earlier that I use on FreeNAS. Originally I intended to bundle them together but reconsidered and now feel they are better off available separately. So here is basically a brief of the changes and what would have been a common README.

If there is actually anyone using the script to back up the configuration via email you really should read on and then update to this version! Continue reading


Quick script to poll parcel status

Sometimes when waiting for a package I like to check the status of it now and then (in reality this means every moment I have over – or rediculously often).
I also like to do things on the command line.

Enter small script of the day;
(this relates to Schenker in Sweden)

%cat schenker.sh
if [ "${1}" = "" ] ; then
cat < Continue reading


Script to check for eol on the command line

I have often wanted a way to check if end of life is getting close for my systems on the command line.
The message in freebsd-update is really nice, but it feels a bit overkill to run that just to check if I should consider updating to a new release of FreeBSD -and it also only checks for the system it is run on..

So I hacked up this little script which checks if EoL is close for either the currently running release of FreeBSD or for the one given as an argument. Now I can have a cron job running every now and then to check for all releases I’m using.

Get it here if you want to give it a try.
Continue reading


I’m in your munin

On this somewhat binary day (101111), I just submitted my first Munin plugin to http://exchange.munin-monitoring.org and once it is approved it should be available at http://exchange.munin-monitoring.org/plugins/system_users/details/ .

It simply lets you graph the number of logged in users with Munin.
Example of the daily graph:
Daily graph in munin for logged in users

For an explanation of what munin is have a look here: http://munin-monitoring.org/
From the site:

Munin is a networked resource monitoring tool that can help analyze resource trends and “what just happened to kill our performance?” problems. It is designed to be very plug and play. A default installation provides a lot of graphs with almost no work.


jails2xml ready for review!

Ok, so after som nice flow and a whole lot of code cleanup I think it is actually presentable now.
So without any further ado, get a copy at http://kosmos.ttyv0.se/attachments/download/41/jails2xml.sh , give it a try and please give me some feedback.
There are a couple of things to be added and updated, this is not “finished”. (like splitting config options at the top to a separate file and giving better granularity to the host info added to the xml.)
But I wanted the chance to get feedback as soon as possible and also might not have as much time to work on this as I would like for a while.

Short description:
This script will with its default options run through your /usr/local/etc/ezjail/ directory and add all the set options for each jail to an xml file called jails.xml in the current directory.
It will also add some info about the host system, and the time of creation of the xml.
So far tested successfully on systems running 7.2-R and 8.0-R.

An anonymized sample of a jails.xml with a single jail configured on the host:
<?xml version="1.0" encoding="iso-8859-1"?>
<exec>/bin/sh /etc/rc</exec>
<allinfo>FreeBSD xxx.xxx 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #0: Tue Jan  5 16:02:27 UTC 2010     [nohide]root@i386-builder.daemonology.net[/nohide]:/usr/obj/usr/src/sys/GENERIC  i386</allinfo>
<verbose>FreeBSD 8.0-RELEASE-p2 #0: Tue Jan  5 16:02:27 UTC 2010     [nohide]root@i386-builder.daemonology.net[/nohide]:/usr/obj/usr/src/sys/GENERIC </verbose>
<generated>Tue Apr  6 20:02:39 CEST 2010</generated>

And just to make sure I am clear about this. This is for FreeBSD systems running jails via the ezjail administration framework.


shell expansion within awk

Say you have a loop in a shell script and want to expand a given variable within an embedded awk statement, this is how:

awk 'BEGIN { FS = "'${i}'" } do some more awking'
In this case $i is my shell variable, and I want to use it as a field separator.

It is just that easy, an extra ‘ to escape awk for a moment and expand $i!


jail resources oneliner

Getting a quick overview of the resources currently assigned to your your jails can be done using the following command sequence:

top -Pajnojid | tail -n 20 | awk '{if ($2!=0) print $0}'

Starring in order of appearance:
top; with the flags P -Show info per CPU, a -get command name from argv[] and not the name of the executable, j -display jail id, n -non interactive mode, ojid -the order flag `o` followed by jid for sorting.
tail; to get the last 20 lines of output (skip the sys info)
awk; print all lines where column 2 is not `0`

if you have many jails and hence many jail processes you might want to bump up the number of lines a bit like follows to show a maximum of 50 processes instead of the default 20:

top -Pajnojid 50 | tail -n 52 | awk '{if ($2!=0) print $0}'