You are currently browsing the HTNet archives for February, 2008.

Keeping oneself motivated throughout a working day can be quite a challenge. There are deadlines approaching, meetings to attend and resources to manage. So what would be the best way to handle a tough working day?

For me, I prefer to do the hard and boring things first thing in the morning. Sure, it doesn’t help establish a good early morning working mood. However as the day progresses, I will do the more interesting and enjoyable tasks.

My reason for sticking with this method is simple, I simply want to be in the most positive mood when I log off from work. This is probably the most important time in my working day.

Why? Because this is the time that I go back home and get together with my family. I don’twant to give them a grouchy first impression just because I had a hard time at work. By doing the tasks I enjoy most at the end of the day, I’m less likely to be in a bad mood.

Starting a working day doing the more challenging tasks also has its benefits. You are most fresh and raring to go within the first three hours of work. Your mind is clearer and thus more able to multi-task.

What about you? How do you tackle your working day? I’m all ears for new tips!

As a server administrator, there’s nothing that bugs me more than services that die all of a sudden. For a web server, an hour’s down time could mean losing a few hundred visitors. This could translate to a loss of advertising income too if you serve ads on your web pages.

I found a snippet of code that I modified to use as a simple service monitoring and restarting tool that I would like to share with all of you.

First off, let me state that I did not write the following script myself. It was adapted from a script I found somewhere (but I didn’t bookmark the source). Just create an empty file and enter the following lines in it:

#!/bin/bash # Services Restarter - Automatically restart httpd and pure-ftpd if they die /bin/netstat -ln | /bin/grep ":80 " | /usr/bin/wc -l | /bin/awk '{if ($1 == 0) system("/sbin/service httpd restart") }' /bin/netstat -ln | /bin/grep ":21 " | /usr/bin/wc -l | /bin/awk '{if ($1 == 0) system("/sbin/service pure-ftpd start") }'

Now just save the file somewhere. As an example, I going to assume that you saved the file as /scripts/svcschk.

So what does the script do? Essentially, the script uses the netstat command line tool to see whether the server is listening on ports 80 (http service) and 21 (ftp service). If the server is not listening to the ports, then it will attempt to start the appropriate services.

Let’s chop the line that monitors the http service into smaller bits so we can understand what’s being done:

/bin/netstat -ln

Invokes the netstat command to list all listening ports and using presenting bound IP addresses in numeric format. The reason we’d want to use the numeric format for IPs is that it is much faster because we’re not resolving the IPs to hostnames.

| /bin/grep ":80 "

We then pipe the output of netstat to grep looking for addresses that are listening to port 80.

If you noticed, we actually checked for ":80 "; ie 80 with a space afterwards. The reason for the space is to filter out other services that run on ports 8000 or 8080 for example, which will be matched if we were to just use :80.

| /usr/bin/wc -l

Next, we pipe the output of grep to wc, which is essentially a command line word counter.

The -l flag used simply tells wc to count the total number of objects passed to it. Since we already grep-ed the relevant ports, this would return either 0 if the service has died or 1 if it’s alive and listening.

| /bin/awk '{if ($1 == 0) system("/sbin/service httpd restart") }'

Following that, we pass the output sent out by wc to awk, a fast text processing engine that can be programmed to do perform simple text processing jobs.

Here, we simply want awk to tell us if the argument passed to it was 0 (the number zero). If this is the case, then run /sbin/service httpd restart (the command to start the httpd service).

To make the script functional, you should set the appropriate ownership and permissions to it. For example: chown root:root /scripts/svcschk; chmod 700 /scripts/svcschk. This will set the ownership of the script to root and make it executable only to this user.

You can then set it to run every minute by adding an entry to your crontab similar to this:

*/1 * * * *    /scripts/svcschk > /dev/null 2>&1

Hope this code snippet and the explanations are useful to you. If you have any questions on them, feel free to ask me by commenting below.

I’ve been contemplating on getting started with AdWords to start promoting some affiliate products. The thing that’s holding me back for now is that I have no idea how the AdWords interface would be like. In addition to that, I’m also not so sure about how keyword prices and bidding process work in AdWords. In fact, I’m worried I could end up losing too much money in the learning process itself.

Then an idea hit me; wouldn’t it be nice for a Google client to have his AdWords account linked to an existing AdSense account? Meaning, he can use the balance of his AdSense income to fund AdWords campaigns.

What do you think? Is this feasible for Google to implement?

After keeping it for quite some time, I’ve decided to release my latest WordPress theme; Uncrufty.

The name is a play on the functionalities and design of the theme itself. I’ll be the first to admit that I’m not a graphics design genius. I also don’t like clutter in my themes (and life in general). So the term Uncrufty is a play of words between the two concepts.

Uncrufty should be compatible with any recent version (2.x; 2.3.x would be better) of WordPress.

You can download it straightaway.