Jun 182015
 

I recently had to verify a whole bunch of servers were responding to SNMP and had the correct DNS reverse look ups in Active Directory.
I used this little script so that it would ask me for an IP address and then do a ping, and then if a server was reachable over ICMP, a nslookup if a server responded to the SNMP Query for the system name.
Continue reading »

Share
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 😀 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 😀

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