Friday, October 31, 2008

SMS Alerts on root logins

Last week I met Anuradha at Kandy and we talked about various stuff. At one time, Anuradha mentioned about this sms alerting method and how we can use that tools in our working environment. So I thought of trying it out (not in an operational server but in a testing server).

There are several ways to get an alert on your mobile phone when there has being a root login in your server. This is not for a critical server set up. There are other better alert systems for those kind of systems. But, for a small business server, home network this is a very cheep and cool solution.


Your server is a GNU/Linux (I used debian/Ubuntu distribution)

What you need :

  • A Mobile Phone with USB cable.
  • smstools package.
  • Your time.
Let's start.

Install smstools.

# apt-get install smstools

Plug in the phone with the USB cable. And get the device name.

# dmesg |grep usb

eg: You should see some thing like /dev/ttyACM0 or similar. If your phone is not detected then you have to troubleshoot that. ;-)

Now you can edit the configuration file and set up the device and baudrate.

# vim /etc/smsd.conf

#init =
device = /dev/ttyACM0
incoming = yes
#pin =
baudrate = 460800

Most of the time you don't have give modem init commands, cos modern phones have their own init commands.

Start the smstools

# /etc/init.d/smstools start

The location where your messages handled is;

$ /var/spool/sms/

There you have several directories.

checked - Messages cued for various checking, and ready to send after checking.
failed - Messages which being failed to send, and the reason for the failure is stated inside the sms
incoming - This is the place where the system stores incoming messages.
outgoing - This is where the message to be sent is stored as a text file.
sent - Messages which sent successfully.

To test your configuration, create a simple text file and put it in the outgoing directory. It should be sent in seconds to the mobile phone number specified in the text file.

Format of the message.

From : Foo
To : 9471XXXXXXX
This is the message, Testing...

If the number specified in the file gets the sms, you are ready to do the real thing. :-) Else you can always manually edit the /etc/smsd.conf or run dpkg-reconfigure smstools and set the values.

Now you want to be alerted via a sms when some one loged in as root to your server locally or remotely.

What I did was very simple. I created the text file in somewhere (/home/user/alert.txt).

From: Server1
To: xxxxxxxxx
A Root Login Detected.

Edit the bashrc file (expecting your default shell is bin/bash) and put the line showed below to get my job done.

# vim /root/.bashrc

And put the following at the end of the file.

cp /home/user/alert.txt /var/spool/sms/outgoing/


What it does is each time some one loged in as root, the text file which I created will be copied to the smstool's outgoing directory and cued. smsd will send it to the phone number I specified in the text file. And a copy of the sent message will stored in the sent directory too. If you want you can clean it later (manually or by using cron with a rm /var/spool/sms/sent/alert.txt).

You have to keep a phone attached to the server and the phone should have credit to send out going messages!!:D

Hope this help.!

Wednesday, October 01, 2008

Word Children's & Elder's Day

Children are the future of the world. We must protect them and guide them to make the world a better place for every species. We must teach them good habits and develop a good mind set on them. If we don't guide them on the right track, future of this world is not going to be a very nice one.!

Elders are those who have made this world what it is now... (I'm NOT referring to the elders who made this world a living hell). They have sacrificed their lives to make ours a better one. So we have to protect our elder generation with love and care.

Thursday, July 03, 2008

My Blog in Sinhala

I started to blog in Sinhala. "Sinhala" is my first language. I thought it would be nice if I keep a separate blog for Sinhala postings. And there in that blog, I will talk about the life, imotions, etc. Less or no technical stuff. And I will write this blog as usual, in English.

My Sinhala Blog is : htpp://


Thursday, May 22, 2008

Synaptic Scrolling Problem

- GSynaptics couldn't initialize. You have to set 'SHMConfig' 'true' in xorg.conf or XF86Config to use GSynaptics -

Is any one there who got this error message when trying to configure your touchpad using gsynaptics? "Yeh I had that message"... I installed Debian lenny by saying "See you later" for my neat, one year and three months old Ubuntu installation. after completing the installation my touchpad's scrolling feature was not working. I googled for a solutoin and found several tips and tricks to overcome this, but didn't help, so had to read up a bit about it and found a way to get it working.

Even though it says "set 'SHMConfig' 'true', it did not work. Then I add the server layout and second InputDevice to the xorg.conf.

Here's what I did to over come the issue.

added this section to the xorg.conf

# vim /etc/X11/xorg.conf

Section "InputDevice"
Identifier "Synaptics Touchpad"
Driver "synaptics"
Option "SendCoreEvents" "true"
Option "Device" "/dev/psaux"
Option "Protocol" "auto-dev"
Option "HorizEdgeScroll" "0"

Then I add the following lines to the bottom of xorg.conf to specify the server layout. I did not have any of the parameters for server layout, so I added all the sections to it.

Section "ServerLayout"
Identifier "Default Layout"
Screen "Default Screen"
InputDevice "Generic Keyboard"
InputDevice "Configured Mouse"
InputDevice "Synaptics Touchpad"

After doing this I restarted the Xserver (Alt+CTRL+Backspace). Scroll works fine! but I still get that error message when I try to run gsynaptics. :-) But for now I'm not going to worry about the gsynaptic, but will have a look at it later.

Tuesday, May 06, 2008

Ceylon Tea Musium

Last weekend I had an opportunity to visit the World's one and only Tea Museum, Ceylon Tea Museum. The museum is located in Hantana, 3KM drive from the beautiful “world's heritage city” Kandy. The museum building itself is an abundant tea factory (built in 1925) for more than a decade.

The museum has 4 floors. Ground floor occupies with heavy machinery like tea rollers, power generators, and other large mechanical equipments which being used in the very first tea factories in Sri Lanka. The first tea roller which were used in year 1889 and many other machineries are displayed in the ground floor. And most of the engines and rollers used over a century ago have being restored to working condition.

When you go to the second floor you will be able to see the whithering process and some other equipments used for drying, and categorizing the tea for various qualities. And there is a section which contains the equipments used by Mr. James Taylor, the father of the tea manufacturing in Sri Lanka. In 1867, Mr. Taylor planted the first tea to be grown commercially in Sri Lanka.

The third floor occupies with more drying racks and two shops where you can buy quality Ceylon tea. And I didn't forget to visit the top floor for a nice warm tea. (for those who don't know, my favourite drink after water is "Tea", I never say no to a cup of tea at any time of the day). While the tea is getting ready, I enjoyed the view from the top floor window. And there was a telescope which we can nicely see the hills belong to Hunnasgiriya region.

I think this museum is a place where every one should visit. A place with a value of informational, and historical, which tells the story of the tasty tea manufacturing in Sri Lanka.

Some facts at a glance;

Location : 3 KM from Kandy town, towards the Hantana road.
Ticket Prices : Students : Rs. 10/= Adults: Rs 25/= (As at 03 -05 -2008)
A friendly staff, with a person who explains every thing through out the tour inside the museum.

My camera was broken that day so could not get good pictures of the factory, but I got some photos from my phone, which are poor in quality. Sorry about that.

Saturday, March 29, 2008

ගනූ/ලිනක්ස් සිංහළෙන්

අද දිනයේ මීගමුව පිහිටි A.G. School of Management Studies හි පැවති ගනූ/ලිනක්ස් වැඩමුලුව අතරදී මා, අනුරාධ, ඩනිෂ්ක, යජිත්, රවිත්, කුංචන (සාකච්ඡාව අතරමැද නිදා ගත්තේය) ගනූ/ලිනක්ස් මෙහෙයුම් පද්ධතියට සිංහළ සහාය මුසු කිරීම පිළිබඳ සාකච්ඡා කළෙමු. මම මෙතෙක් කළක් සිංහළ ලිනක්ස් පිළිබඳ අවධානයක් යොමු නොකිරීම පිළිබඳ කණගාටුචක් ඇති වූ අතර අද සිට හෝ ඒ හා සම්බන්ධ ව්‍යාපෘතියකට සම්බන්ධව කටයුතු කිරීමට අසහස් කළෙමි.

අද දින මෙම ස්ථානයේ පැවති වැඩමුලුව සඳහා සිසුන් 50 කට ආසන්න ප්‍රමාණයක් පැමිණි අතර ඔවුන් සියලු දෙනාම ලිනක්ස් මෙහෙයුම් පද්ධතිය පිළිබඳ දැඩි උනන්දුවක් හා කැමැත්තක් දැක්වූහ. මෙම මොහොතේ (රාත්‍රී 11.55) මම, කුංචන, යජිත්, චනුක, ඩනිෂ්ක A.G. School of Management Studies ආයතනයේ පරිඝණකාගාරයේ අවදියෙන් සිටින අතර අනුරාධ මුලින් අප හා සිටින බව කීවද හවස් යාමයේදී පැන යන ලදී. :-)

හෙට දින මෙම වැඩමුලුවේ දෙවෙනි සහ අවසන් දිනයයි. තව ස්වල්ප වේලාවකින් මා නිදා ගත යුතු වේ. දැනට නවතිමි.

Saturday, March 15, 2008

Workshop on Unix (GNU/LInux) Shell

We (LKLUG) organized a workshop on Unix Shell, to provide some hands on training about the Unix Shell. We used GNU/Linux, a Unix like Operating system as our platform. Today is the first day of the workshop where we covered basics of the shell.
  • Introduction to Shell by Anuradha R.

  • Basic Filters by Bud

  • Advanced Shell usage by Sapumal

We conducted this workshop in the Lanka Software Foundation's Lab at UCSC. We expected 20 participants but there were around 25! Since we planed this as a geek's event we didn't mind standing positions and shared seats. :-) Right now Sapumal is conducting his session, the last session for the day and tomorrow we'll cover up some more advanced stuff in Shell Scripting.
Anuradha's Session.

Bud's Session.

Sapumal's Session.

Sunday, January 27, 2008

Insert a copy right label to a set of photos.

Most of us have photo galleries in the Internet. And we upload hundreds of thousands of photos to the Internet. I started to use this nice image manipulation tool named "Imagemagick" to insert a label (a copy right label or some thing) to a set of photos at a one go. since I felt it's very easy to do it by saving it as a script so I can just run it any time I want. Imagemagick is a very famous tool and it has various set of tools to manipulate images. You can check the man page for all the commands and syntaxes, or from web too. Since couple of people asked about this from me I thought of sharing it among all. Imagemagick is available for Mac, Unix and Windows platform too. But I'll stick to my favourite GNU/Linux way of doing it.

First check whether imagemagick is already installed in your system

In Debian based systems issue this command and see the result

#dpkg -l | grep imagemagick

If you don't have the package, install it using your favourite method. I used the apt.

#apt-get install imagemagick
I have collect all the steps and create the script below and run it inside the directory where the photos are located. Actually I reduced the image size to suite for upload, and reduce the quality a bit too. Then inserted the label to all the photos and finally open the photos in gthumb image viewer. First of all it copies all the photos in to a directory to preserve the originals. So you always have the original photos you've taken.

echo "Resize, Convert, prepare photos to publish for web.";
echo "==================================================";
ls *JPG;
mkdir temp
cp *JPG temp
cd temp
for PICME in `ls *JPG`; do convert $PICME -resize 800x600 -quality 80% $PICME; done
echo "Photos resized to 800 x 600";
for PICME in `ls *JPG`; do convert -pointsize 12 -fill Black -draw 'text 20 20 "Copyright 2007. M.D.D.Anuradha Mallikarachchi. All rights reserved."' $PICME $PICME; done
echo "Label inseted."
gthumb *

You can see the inserted label, at the top right of the photo. and it's very convenient for me, when I have to insert a label for set of photos at a one go.

Oh don't forget to make the script executable (chmod +x script) and put it in /usr/local/bin.

Hope this will be useful to some one. :-)