Friday, November 28, 2008

Ping Every Host in /etc/hosts File.

If you want to know whether hosts specified in /etc/hosts file are reachable, just give the following command:

$ awk '/^[0-9]/{print $1}' /etc/hosts | xargs -l ping -c 1 $1

Sample run:

$ awk '/^[0-9]/{print $1}' /etc/hosts | xargs -l ping -c 1 $1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.046 ms

--- 127.0.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.046/0.046/0.046/0.000 ms
PING 127.0.1.1 (127.0.1.1) 56(84) bytes of data.
64 bytes from 127.0.1.1: icmp_seq=1 ttl=64 time=0.028 ms

--- 127.0.1.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.028/0.028/0.028/0.000 ms


Friday, November 7, 2008

Missing Linux Entry in GRUB Menu

If any Linux entry is not present in GRUB menu,
you can visit following forum to view a solution.

Linux Forum: Unable to see Fedora 7 in GRUB Menu

Wednesday, November 5, 2008

Finding Best Linux Distribution

We can find ranking of Linux distributions (distros) at site distrowatch.com. This ranking is based on Page Hits Per Day.In order to find best Linux distro, I have written a Perl script:

#!/usr/bin/perl -w
#===============================================================================
#
# FILE: best_distro.pl
#
# USAGE: ./best_distro.pl
#
# DESCRIPTION: Finds best distro from distrowatch.com
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Mitesh Singh Jat (mitesh)
# VERSION: 1.0
# CREATED: Tuesday 04 November 2008 04:05:19 IST
# REVISION: ---
#===============================================================================

use strict;
use warnings;

my $ndistro = 1;

if (@ARGV >= 1)
{
$ndistro = $ARGV[0];
if ($ndistro > 100)
{
$ndistro = 100;
}
}

my $lynx = `which lynx`;
chomp($lynx);
if ($lynx eq "")
{
print STDERR "$0: please install lynx\n";
print STDERR "sudo apt-get install lynx\n";
exit(-1);
}

open(LYNX, "lynx -source http://distrowatch.com/ |") or die("$0: cannot open lynx: $!\n");

my $i = 1;

while ($i <= $ndistro)
{
my $line;
my $distro;
my $rank = "";
while ($line = <LYNX>)
{
chomp($line);
$line =~ s/<th class=([^>]*)>(.*?)<\/th>/$2/i;
$line =~ s/(\s+)//g;
if ($line eq "$i")
{
$rank = $line;

unless ($line = <LYNX>) {last;}
chomp($line);
$line =~ s/<td class=([^>]*)><a href=([^>]*)>(.*?)<\/a><\/td>/$3/i;
$line =~ s/(\s+)//g;
$distro = $line;

print "$rank\t$distro\n";
last;
}
}
++$i;
}

close(LYNX);

Sample runs of above program:
$ ./best_distro.pl
1 Ubuntu
$ ./best_distro.pl 5
1 Ubuntu
2 openSUSE
3 Mint
4 Fedora
5 Debian

Tuesday, November 4, 2008

Counts from min to max

In order to get counts from start number to end number,
I have written a shell script.


#!/bin/sh

if [ $# -ne 2 ]
then
echo "Usage: $0 min max"
exit
fi


min=$1
max=$2

while [ $min -le $max ]
do
echo -n $min " "
min=`expr $min + 1`
done
#end script



Sample run:
$ ~/bin/count.sh 2 5
2 3 4 5

Tip: This is very handy script, that is very helpful
in getting counts in the loop. For example:
$ for i in `~/bin/count.sh 2 8`
> do
> echo "Hello $i"
> done

Hello 2
Hello 3
Hello 4
Hello 5
Hello 6
Hello 7
Hello 8