...making Linux just a little more fun!

2-Cent Tips

2-cent tip: Checking HTTP servers

Thomas Bonham [thomasbonham at bonhamlinux.org]


Sat, 14 Jun 2008 20:20:42 -0700

Hi All,

I will share the socket code that I wrote for checking to see if your http server is running. This will need to be run from a remote computer.

There will be something that you may need to change some things around for your needs and at this time it will not work with https it is only for http.

Here is the code I have put a few notes in where you may need to change for your needs.

#!/usr/bin/perl
use Socket;
$host = $ARGV[0];
$port = $ARGV[1];
$iaddr = inet_aton($host) || die "Unable to determine address for $host";
$paddr = sockaddr_in($port, $iaddr);
$proto = getprotobyname('tcp');
socket(SOCKET, PF_INET, SOCK_STREAM, $proto) ||
    return "Unable to create a new socket: $!";
connect(SOCKET, $paddr) || die "Connection refused by $host: $!";
select(SOCKET);
$| = 1;
select(stdout);
print SOCKET "GET / HTTP/1.1\n";
print SOCKET "Host: $host\n";
print SOCKET "Connection: close\n";
print SOCKET "\n";
my $i = 0;
while (<SOCKET>) {
    if($i < 1) {
        # May need to change to match what header you would like back
        if($_ !~/^HTTP\/1.1 200 OK/) {
            # Do something here
        }
        break;
    }
    $i++;
}

Thomas


2-cent tip: Speeding up Knoppix

Ben Okopnik [ben at linuxgazette.net]


Sat, 28 Jun 2008 20:24:33 -0400

----- Forwarded message from Oscar Laycock <oscar_laycock@yahoo.co.uk> -----
 
   I run a Knoppix CD on an old PC with only 128 meg of RAM. To speed things
   up, to reduce the swapping, I cut down on the memory set aside for my
   work:
 
   mount -t tmpfs /ramdisk /ramdisk -o remount,rw,size=15m,mode=755
 
   Maybe you can do something similar on other live CD's?
    
----- End forwarded message -----
-- 
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *


2-cent tip: Removing the comments out of a configuration file

Thomas Bonham [thomasbonham at bonhamlinux.org]


Fri, 06 Jun 2008 07:51:55 -0700

Hi All,

I thought I would sure this little perl script that will remove the comments out of a configuration file.

#!/usr/bin/perl -w
# Thomas Bonham
# 06/06/08
 
if($#ARGV !=0) {
    print "usage: path to the configuration\n";
    exit;
}
$fileName=$ARGV[0];
open(O,"<$fileName") || die($!);
open(N,">$fileName.free") || die($!);
while(<O>) {
    next if($_  =~/^#.*/) ;
    print N $_
}

Thomas

[ Thread continues here (16 messages/15.65kB) ]


Talkback: Discuss this article with The Answer Gang

Copyright © 2008, . Released under the Open Publication License unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 152 of Linux Gazette, July 2008

Tux