Apr 132012
 

Hey Everyone

I have just finished making my very first bash script. It’s called Simple Log File Monitor as you may have guessed.
It reads in a log file, either from the beginning or from a mark that the script has set before, then it can perform a user defined action to the output of the log file after it has been read.
It will then apply an action to the resultant output of the logfile, e.g. email it to you.

I have written it in shell script in order for it to be small, and as reliant on as little as possible.
You should be able to run this script with just bash, awk, grep, tail, date, and wc.
The purpose of this was for a router that I plan to build. I didn’t want to install perl onto it as it will have miniscule storage, so I thought this was a better option. This script should also work on any embedded devices that have the required utilities installed, so if there is anyone out there who has one of those, I’d appreciate any testing that could be done on those devices.

This script allows you to set a configuration file with the -c switch when you run the script, but if you don’t set it, the script will use the default slfm.conf that should be located in the same directory as the script itself.

This allows you to customise when the log file is monitored, and which files are monitored by running the script at certain intervals with different command line parameters.
So the script will show the last hours worth of logs if the script is run hourly.

The script will mark it’s position so that it won’t have to read the whole entire logfile again, and then it can redirect the output of the logfile to anywhere. For example it can email you the results, or it can append the results to a file.

The documentation on this isn’t great at the moment so any help with that would be appreciated.
If anyone could please try this script out and provide feedback in the comments section, that would be great.
As this is my first script, please be gentle :D but I’m open to any suggestions on how to make this better.

This script can be downloaded from my sourceforge page.
It has a sample configuration file already included to help you get started. Hopefully it’s understandable enough and clear enough to everyone and easy enough to work with.
Hope to hear back from some new users :D

Share

Mar 112012
 

Recently I had some issues with my free DNS service, it wasn’t updating my DNS so I couldn’t access my server remotely.
After this happened a few times, I decided to modify one of the configuration files so that it would email me my external IP address each time the PPP connection came up. This ensured that I would get the latest IP address emailed to me ASAP.

What You Will Need :

Sendmail or equivalent on the linux box that you doing this on.
The PPP connection needs to be on the linux box also for this tutorial, however I will write up a guide that uses an external website instead later on.
A commandline mail sending program, I have used mailx in this example, which is symlinked to mail.

How To Do It :

To do this, I added a file in this directory ( on my Debian System ) –

/etc/ppp/ip-up.d/

which I have named “EmailIP”.
Scripts in this directory are run when the ppp connection goes up.

The file contains the following line which does the gruntwork

echo Connection has come up - New IP Address : `ifconfig ppp0 | grep inet | awk -F' ' '{ print $2 }'|awk -F: '{print $2}'` | /usr/bin/mail -r <From@example.com> -s IP-Address <Email@example.com>

What that command does is pipe the text “New IP Address : ” followed by the output of ifconfig ppp0 which is then grepped down to the inet line, and then awked down to the actual IP address and pipe it into the mail command which can send an email via sendmail or whatever mail daemon you have installed.
The sendmail command has the following parameters specified –
-r : specifies the address that the email appears to be coming from (From@example.com in the example)
-s : specifies the subject of the email (IP-Address in the example)
Email Address (Email@example.com in the example)

Then once you have the script in place, when the ppp connection goes down then comes back up, you should get an email to the email address you specified with the text “Connection has come up – New IP Address : <Your New IP Address>

Share

Jan 292012
 

SystemRescueCD is very useful to have on hand for those issues that come up at the worst times. Instead of having to dig for that USB key or CD that SystemRescueCD is on, I’ve setup my PXE server with SystemRescueCD to save time on having to find where I’ve put the CD. It also means that when SystemRescueCD is updated, all I need to do is update the files on my PXE server instead of having to burn a new CD or install it again on a USB key which means less clutter for me which is always good.

The only downside to booting over the network is the time it takes to boot if you’re still on good ol’ 100 megabit “Fast” Ethernet as SystemRescueCD weights in at just over 300 megabytes, which also means the system that you’re network booting on must have at least 512 megabytes of ram in order to network boot SystemRescueCD as all the data is stored in RAM when you networkboot.

Anyways, onto the nitty grittys.


Step 1 – Getting the SystemRescueCD files

We need the ISO file that contains the files we will need to PXE boot SystemRescueCD which can be downloaded from here.
Once we have the ISO file, we need 4 files off the ISO file, which are –

  • initram.igz – this is the initial ramdisk that SystemRescueCD uses to boot
  • rescuecd – This is the kernel that SystemRescueCD uses, however there are other options that can be used.
  • sysrcd.dat – This contains the squash file system that becomes the root filesystem for SystemRescueCD
  • sysrcd.md5 – This is the signature file for SystemRescueCD, and isn’t actually needed, but good idea to have.

Once we have these 4 files, we need to place them onto our PXE server. I have used the directory /tftpboot/srcd for my files on the server.

Step 2 – Configuring the PXE Server

We will need to edit the file that contains the configuration for the PXE server. If you have been following my PXE Server guide then the file is called default in the pxelinux.cfg directory.
Using your favourite text editor, add the following lines to the configuration file –

LABEL SRCD
MENU LABEL SystemRescueCD 2.4.1
kernel srcd/rescuecd
append initrd=srcd/initram.igz netboot=tftp://10.1.1.1/srcd/sysrcd.dat

The last two lines will need customisation to your setup if you use a different kernel, or the IP address of your PXE server is different, as will the path for the kernel, initram and netboot parameters.

Once the configuration file is updated, you should now be able to boot SystemRescueCD over the network with little difficulty, however if the network has some issues you may find it will take a little while as the TFTP protocol sends data over UDP which does not support resending corrupted data.

Share

Oct 082011
 

A few months ago, I had a post detailing how to setup a streaming webcam server.

Recently, I found an Android app that let me view it on my mobile phone as well which let me use the camera as a baby cam.
The app is called “Tinycam Monitor” and comes in a free and a paid version.
You can use the free version to do stream the webcam but if you like it, please get the paid version to support the developer :).

So, step 1 is to first get the application onto your phone.
This can be done from the market just like any other application.

Step 2 is to configure the app to view the webcam stream.
Once you open the application, in the main menu touch “Manage cameras”

Remove any default cams that may be there, then hit menu and press on “Add camera”
You will see a new camera come up in the list, touch on the pencil to edit the camera.
In the camera options, go down to “Advanced Settings” and edit the parameter
Edit JPEG image address needs to be set to your webcam stream that you setup in the previous post.
For Example : http://10.0.0.1/webcam.mjpeg

Once that is entered, hit back, and press “Camera Status” to ensure that you can connect to the camera.
Once that is succesful, you can now view your webcam stream on your Android phone via the app.

Share

Jul 262011
 

Hi All,

I just bought my daughter a digital camera for her to take photos with since she loves taking them.
It’s one of these, which we bought at Toys ‘R’ Us for $25, which was a pretty good deal.

Look like this :
Kidz Camera

Once we got home, she exhausted the tiny internal memory fairly quickly, so I had to download the photos off the camera.

Only problem, the bundled software only supports Windows. I don’t have a Windows machine anymore though, so off to the internet I trundle to find out how to get the photos off the camera.

After lots of trawling, I come across a snippet from a post a while back mentioning gphoto2.
So off I go to install gphoto2, and what do you know, I can now download all the photos off the camera in ppm format.

To do it, I plugged the camera in via USB, after I plugged it in, the camera was detected by my eeePC.
The lsusb command spat out

Bus 003 Device 003: ID 0979:0227 Jeilin Technology Corp., Ltd

that as the camera, which was a bit cryptic but that’s ok, as long as it was picking it up.

After I plugged it in, I used gphoto2 to check out the camera to see what was on it.

I ran –

gphoto2 -L

to see what was on it, and it spat out –


There are 39 files in folder '/'.
#1 jl_001.ppm image/x-portable-pixmap
#2 jl_002.ppm image/x-portable-pixmap
#3 jl_003.ppm image/x-portable-pixmap
#4 jl_004.ppm image/x-portable-pixmap

So gphoto2 can definitely read the camera. Next step – to download all the photos.

I ran –

gphoto2 -P

to download all the photos to the current directory.
After running it, I got this –

Downloading 'jl_001.ppm' from folder '/'...
Saving file as jl_001.ppm
Downloading 'jl_002.ppm' from folder '/'...
Saving file as jl_002.ppm
Downloading 'jl_003.ppm' from folder '/'...
Saving file as jl_003.ppm

And all the photos were saved to the current directory.
So that’s how I downloaded all the photos off the Sakar Kidz Cam.

Hope this helps someone in need !.

Share

Jul 192011
 

Hi All, just a quick update today.

I was trying to get NFS working today but kept running into errors.
Whenever I tried to start imapd, I would keep getting this error –

rpc.idmapd[12599]: main: fcntl(/var/lib/nfs/rpc_pipefs/nfs): Invalid argument

Turns out, I didn’t have dnotify support enabled in the kernel.
Enabling this now, and will be testing very soon.

Just a quick tip for anyone coming across this issue !

Cheers all.

Share

Jun 082011
 

A continuation of this post.

You can also create machine specific configuration files by naming the file the same as the mac address but replacing the colons ( : ) with dashes ( – ) and adding a 01 to the front to signify that this is an ethernet address..
So 00:15:af:69:31:79 becomes 01-00-15-af-69-31-79.

This is also the “BOOTIF” that you see on the previous screenshot.

Share

May 192011
 

Hi All,

I’m in the process of setting up PXE for some computers of mine, but I wanted them to have a separate configuration file as they do not have the power to run some of the other options, so I don’t want them to show up. I didn’t want to define specific IP addresses for the computers either or use IP specific configuration files as IP address may change.

So, what I did is to make a configuration file with the SYSUUID as the filename, since the SYSUUID is based off the mac address of the computer.
Then when it loads, the computer will boot off the SYSUUID configuration file instead of the default one.
You can find the SYSUUID on the boot page when a computer is booting from the network.

The SYSUUID is outlined in red, and quite long, but if a file is named that then the computer will boot off it, as that one is currently doing.

Share

May 172011
 

Hi All,

In my previous post regarding booting Tiny Core Linux over PXE, we were booting a premade image that did not have much installed by default.
In this post, we will remaster the image into something usable that we can boot off by extracting all the files that we need and merging the directories then repacking it all into one. One of the advantages of doing it this way is that it lets you modify all the files in the root file system before you repack it all up.

What we will need to do is to get the tcz files for the applications we want to install, and merge them into the default tinycore.gz image. This will result in a larger tinycore.gz file but when the image is booted, applications will be pre-installed. This can be useful for diskless workstations in an office or netcafe for example.

So, onto the hard parts.


Step 1 – Getting the TCZ files

Ok, so once we’ve decided what software we want, we will need the TCZ files for the software we want.