Thursday, October 15, 2009

Removing ^M (Ctrl +M) characters

Time to time we have to delete ^M charaters in *nix from a files, here is a simple script which will do it fast.

# To remove ctrl+M character from txt file in solaris
# Date: 2009-02-06

if [ -f $1 ]
tr -d '\15' < $1 >newname
mv newname $1

Script first remove the ^M characters and then move the file to same filename.

Wednesday, October 14, 2009

Nagios Read Only Access

Today I got a task to provided Nagios Read Only Web access to Contact Centres, and Google for a 2 minutes tells that a nice guy Derrick have written a readonly cgi patch for Nagios.

When I tries to patch the Nagios source it give error...

Reversed (or previously applied) patch detected! Assume -R? [n]

Which mean I did have missed something "ChangeLog" between Nagios version 3.0.x to 3.2.x, hey no more manual patching is required if you are running latest version of Nagios, as the Nagios Team have included the patch into the Nagios Core :)

So all one have to do is to add all the users to Nagios cgi.cfg file directive...


That's all, thumb up for Derrick for the nice patch and thanks to Nagios team for including it in the Core.

Tuesday, October 13, 2009

Installing configuring Gnokii on Linux

Gnokii provides tools and a user space driver for use with mobile phones under various operating systems (most testing is done under Linux but also Solaris, *BSD family and MS Windows families are known to work. Using Gnokii one can send/receive SMS, phonebook, call management and others.

Installation from rpm manager (yum)

Gnokii package is available via most of Linux distro repository, on Fedora 10 the below will install the gnokii package if not then do the installation from source.

yum install gnokii

Installing from Source:

1. Download the gnokii source download.
2. Untar the source and change (cd) to gnokii source directory


./configure (to configure)
make (to compile)
make install (to install the binaries)

Copy the example config file for gnokii from the Docs/sample/ directory to your home directory:

$ cp Docs/sample/gnokiirc ~/.gnokiirc

If you copied the .gnokiirc file to your home directory (not root) then do not forget to add your shell user account to uucp otherwise you wouldn't able to use gnokii due to permission problem on serial device you setup in .gnokiirc file.

$ groups
askar wheel uucp

I have tested Gnokii with my Motorola L6/L7 cell phones check whether your phone is supported or not. (Tip.


Gnokii uses gnokiirc file for all this configuration, if gnokii has been installed via package manager then most probably it may have installed a /etc/gnokiirc file, the settings in this file will be used in the absence of a .gnokiirc file in your home directory.

Below is the minimum setting we need.

Note: usually you only need to edit the port and model part only

port = /dev/ttyACM0 # Set to port on which your phone is connect Tip: check /var/log/messages ]
model = AT
initlength = default
connection = serial
use_locking = no
serial_baudrate = 19200
smsc_timeout = 10
allow_breakage = 0
bindir = /usr/sbin/
#TELEPHONE = 12345678
debug = off # Turn it on for debugging
rlpdebug = off
xdebug = off

While phone is connected and /etc/gnokiirc or .gnokiirc has been setup properly.

2. Check if you phone has been recognize by gnokii.

gnokii --identify

GNOKII Version 0.6.27
IMEI : IMEI359411000810925
Manufacturer : Motorola CE, Copyright 2000
Model : GSM900","GSM1800","GSM1900","GS
Product name : GSM900","GSM1800","GSM1900","GS
Revision : R4513_G_08.B7.DCR_R

This is what I get for my Motorola L7 connected with via USB cable with my laptop running Fedora 10.

Note: you should see gnokii identified your cellphone/gsm modem, if you don't see it, update your ~/.gnokiirc or /etc/gnokiirc to suit your need

Note: During testing use 'root' account or you will need read/write permissions on whatever serial port you specify in /etc/gnokiirc or .gnokiirc file.

Using Gnokii

All the below information and more can be found here.

Backup & Restoration of phonebook on phone SM card using gnokii


gnokii --getphonebook SM 1 end --vcard > myphonebook.vcf


gnokii --writephonebook --vcard \< myphonebook.vcf

Handling calls

To dial a voice call:

gnokii --dialvoice 12345678

SMS Sending and Receiving

Use smsd if you need both to send and to receive SMS. You can use it with a file or a database backend.

If you only need to send, you can also use gnokii --sendsms, which reads message body from stdin.


echo "This is a test message" | gnokii --sendsms +12345678


gnokii --sendsms +12345678
type your text and press

Ctrl+d to exit.

You can also use the utils/sendsms bash script that uses a text based interface using dialog as a more friendly frontend to gnokii --sendsms, allowing you to pick recipient numbers from your phonebooks instead of typing them on the command line.

In my next article you can learn how to use Gnokii + Nagios for sending SMS Notifications from Nagios whenever there is problem with any of the monitored host/service

Sunday, October 11, 2009

SUSE Studio

SUSE Studio is a ...

  • SUSE Studio is a simple and fast appliance builder.
  • It provides an easy to use, web-based user interface and will run in your browser without other needed software.
  • One great feature is the SUSE Studio Testdrive. You can boot, configure and test your appliance in a browser window without download.
I have used to to create customize Suse (Gnome Desktop) and Minimal X Vmware images which later I have booted with Virtualbox. One can easily convert images created for vmware to virtualbox.

I like Suse Studio and its kinda revolution in the field of OS.

Monday, October 5, 2009

Checking invalid SSH attempts

Running the following will gives the unique count of invalid SSH attempts on Linux server.

sudo awk 'gsub(".*sshd.*Failed password for (invalid user )?", "") {print $1}' /var/log/secure | sort | uniq -c | sort -rn | head -10

Or all of the /var/log/secure* files

sudo awk 'gsub(".*sshd.*Failed password for (invalid user )?", "") {print $1}' /var/log/secure* | sort | uniq -c | sort -rn | head -10