explore the neighborhood by looking at the PTR for the whole /24

Looking up the PTR resource records / reverses of the /24 neighbourhood of an IP address reveals lots of connections.
To do so I use two bash functions. One function for printing all the reverses and one for creating an html file with pointers to more information.

I named the first function ptr24 and it looks like.
g0:~$cat .bashrc | head -14
function ptr24 {
CNET=`echo $1|awk -F"." '{print $1"."$2"."$3}'`
echo "PTR lookup for $CNET.0/24"
for i in `seq 0 255`;do
	
	CUR=`dig +short -x $CNET.$i`;
	if [ -n "$CUR" ]; then
		echo -n "$CNET.$i -> ";
        	echo $CUR;
	fi
	
done
}


So, if for example we want to explore the neighbourhood of the gnu.org web server we could that.
g0:~$dig +short gnu.org
140.186.70.148
g0:~$ptr24 140.186.70.148
PTR lookup for 140.186.70.0/24
140.186.70.1 -> ge-core1.qcy.gnu.org.
140.186.70.10 -> fencepost.gnu.org.
140.186.70.11 -> leviathan.gnu.org.
140.186.70.13 -> mail.fsf.org.
140.186.70.14 -> gnusenet.gnu.org.
140.186.70.15 -> fencepost-ssh.gnu.org.
140.186.70.17 -> lists.gnu.org.
140.186.70.20 -> ftp.gnu.org.
140.186.70.21 -> alpha.gnu.org.
140.186.70.22 -> ftp-upload.gnu.org.
140.186.70.23 -> webmail.fsf.org.
140.186.70.25 -> livestream.fsf.org.
140.186.70.26 -> sandbox.gnewsense.org.
...
140.186.70.154 -> shop-dev.fsf.org.
140.186.70.155 -> testtaranis.gnu.org.
140.186.70.156 -> gplv3.fsf.org.
140.186.70.157 -> audio-video-dev.gnu.org.
140.186.70.253 -> ge-sw1.qcy.gnu.org.
g0:~$

I named the second function ptr24htm and looks like this.
g0:~$cat .bashrc |head -28|tail -15

function ptr24htm {
CNET=`echo $1|awk -F"." '{print $1"."$2"."$3}'`
echo "PTR lookup for $CNET.0/24<br />"
for i in `seq 0 255`;do

CUR=`dig +short -x $CNET.$i`;
if [ -n "$CUR" ]; then
    echo -n "$CNET.$i -> ";
    echo "<a href=http://ipduh.com/dns/?$CUR>$CUR</a><br />";
fi

done
}


To produce a ptr.html with the information related to gnu.org we can do the following.
g0:~$ptr24htm `dig +short gnu.org` > ptr.html
g0:~$

The ptr.html looks like
PTR lookup for 140.186.70.0/24
140.186.70.1 -> ge-core1.qcy.gnu.org.
140.186.70.10 -> fencepost.gnu.org.
140.186.70.11 -> leviathan.gnu.org.
140.186.70.13 -> mail.fsf.org.
140.186.70.14 -> gnusenet.gnu.org.
140.186.70.15 -> fencepost-ssh.gnu.org.
140.186.70.17 -> lists.gnu.org.
140.186.70.20 -> ftp.gnu.org.
140.186.70.21 -> alpha.gnu.org.
140.186.70.22 -> ftp-upload.gnu.org.
140.186.70.23 -> webmail.fsf.org.
140.186.70.25 -> livestream.fsf.org.
140.186.70.26 -> sandbox.gnewsense.org.
140.186.70.30 -> svnweb.fsf.org.
140.186.70.31 -> spamhaus-rsync.fsf.org.
140.186.70.32 -> defectivebydesign.org.
140.186.70.33 -> galactica.fsf.org.
140.186.70.34 -> catalyst.fsf.org.
140.186.70.35 -> archive.gnewsense.org.
140.186.70.36 -> littlenemo.fsf.org.
140.186.70.37 -> labyrinth.fsf.org.
140.186.70.38 -> sycophant.fsf.org.
140.186.70.39 -> zaphod.gnu.org.
140.186.70.40 -> agilus.fsf.org.
140.186.70.41 -> bluemchen.kde.org.
140.186.70.42 -> agia.fsf.org.
140.186.70.43 -> debbugs.gnu.org.
140.186.70.44 -> config.fsf.org.
140.186.70.45 -> jamsession.fsf.org.
140.186.70.46 -> groups.fsf.org.
140.186.70.47 -> UNUSED-47.gnu.org.
140.186.70.48 -> tor.fsf.org.
140.186.70.49 -> archive.fsf.org.
140.186.70.50 -> smtp.member.fsf.org.
140.186.70.51 -> colonialone.fsf.org.
140.186.70.52 -> mirror.fsf.org.
140.186.70.53 -> sunjammer.sugarlabs.org.
140.186.70.54 -> linux-libre.fsfla.org.
140.186.70.56 -> news.swpat.org.
140.186.70.58 -> zope.fsf.org.
140.186.70.59 -> www-old.fsf.org.
140.186.70.60 -> my.fsf.org.
140.186.70.61 -> ldap.fsf.org.
140.186.70.62 -> code.autonomo.us.
140.186.70.63 -> www-dev.fsf.org.
140.186.70.64 -> my-dev.fsf.org.
140.186.70.65 -> cloud9.fsf.org.
140.186.70.66 -> blag.fsf.org.
140.186.70.67 -> windows7sins.org.
140.186.70.69 -> ftp-dev.gnu.org.
140.186.70.70 -> savannah.gnu.org.
140.186.70.71 -> savannah.nongnu.org.
140.186.70.72 -> vcs.savannah.gnu.org.
140.186.70.73 -> download.savannah.gnu.org.
140.186.70.74 -> mgt.savannah.gnu.org.
140.186.70.75 -> internal.savannah.gnu.org.
140.186.70.76 -> vpn.savannah.gnu.org.
140.186.70.80 -> groups-dev.fsf.org.
140.186.70.81 -> cas.fsf.org.
140.186.70.82 -> jabber.fsf.org.
140.186.70.83 -> brains.fsf.org.
140.186.70.84 -> balance.fsf.org.
140.186.70.85 -> eccles.gnewsense.org.
140.186.70.86 -> bloodnok.gnewsense.org.
140.186.70.87 -> seagoon.gnewsense.org.
140.186.70.88 -> config.gnewsense.org.
140.186.70.89 -> elpa.gnu.org.
140.186.70.90 -> heinlein.fsf.org.
140.186.70.91 -> mycroft.fsf.org.
140.186.70.92 -> eggs.gnu.org.
140.186.70.93 -> columbia.fsf.org.
140.186.70.94 -> directoryng-dev.fsf.org.
140.186.70.95 -> resolver1.fsf.org.
140.186.70.96 -> crm.fsf.org.
140.186.70.97 -> vinge.fsf.org.
140.186.70.98 -> nonce.fsf.org.
140.186.70.99 -> id-dev.fsf.org.
140.186.70.100 -> treehouse.sugarlabs.org.
140.186.70.101 -> UNUSED101.sugarlabs.org.
140.186.70.102 -> lightwave.sugarlabs.org.
140.186.70.103 -> UNUSED103.sugarlabs.org.
140.186.70.104 -> dextrose.sugarlabs.org.
140.186.70.105 -> UNUSED105.sugarlabs.org.
140.186.70.106 -> pootle.sugarlabs.org.
140.186.70.107 -> usr.sugarlabs.org.
140.186.70.108 -> UNUSED108.sugarlabs.org.
140.186.70.109 -> template-lucid.sugarlabs.org.
140.186.70.110 -> identity.sugarlabs.org.
140.186.70.111 -> UNUSED111.sugarlabs.org.
140.186.70.112 -> zatoichi.sugarlabs.org.
140.186.70.113 -> openlesson.sugarlabs.org.
140.186.70.114 -> UNUSED114.sugarlabs.org.
140.186.70.115 -> buildslave-ubuntu-lucid-64bit.sugarlabs.org.
140.186.70.116 -> UNUSED116.sugarlabs.org.
140.186.70.117 -> UNUSED117.sugarlabs.org.
140.186.70.118 -> UNUSED118.sugarlabs.org.
140.186.70.119 -> UNUSED119.sugarlabs.org.
140.186.70.120 -> UNUSED120.sugarlabs.org.
140.186.70.121 -> booki.treehouse.su.
140.186.70.122 -> anno.treehouse.su.
140.186.70.123 -> aslo-web.sugarlabs.org.
140.186.70.124 -> status.treehouse.su.
140.186.70.125 -> rt.sugarlabs.org.
140.186.70.126 -> schooltool.sugarlabs.org.
140.186.70.127 -> mapspress.sugarlabs.org.
140.186.70.128 -> monitoring.treehouse.su.
140.186.70.129 -> idea.sugarlabs.org.
140.186.70.130 -> dirac.fsf.org.
140.186.70.131 -> www.fsf.org.
140.186.70.132 -> lists.fsf.org.
140.186.70.133 -> testlucid.gnu.org.
140.186.70.134 -> resolver2.fsf.org.
140.186.70.135 -> seeder.gnu.org.
140.186.70.136 -> edit.fsf.org.
140.186.70.137 -> crm-dev.fsf.org.
140.186.70.138 -> logger.fsf.org.
140.186.70.139 -> dbd-dev.fsf.org.
140.186.70.140 -> social.gnu.org.
140.186.70.141 -> wiki-dev.swpat.org.
140.186.70.142 -> news-dev.swpat.org.
140.186.70.143 -> wiki.swpat.org.
140.186.70.144 -> bluemchen2.kde.org.
140.186.70.145 -> termite.fsf.org.
140.186.70.146 -> airhorn.fsf.org.
140.186.70.147 -> directory-dev.fsf.org.
140.186.70.148 -> wildebeest.gnu.org.
140.186.70.149 -> goodbye.gnu.org.
140.186.70.150 -> directory-p.fsf.org.
140.186.70.151 -> www.nongnu.org.
140.186.70.153 -> bitcoin.fsf.org.
140.186.70.154 -> shop-dev.fsf.org.
140.186.70.155 -> testtaranis.gnu.org.
140.186.70.156 -> gplv3.fsf.org.
140.186.70.157 -> audio-video-dev.gnu.org.
140.186.70.253 -> ge-sw1.qcy.gnu.org.

Install and configure PostgreSQL in Ubuntu 10.04.* LTS

The following process works for Ubuntu 10.04. It should work or at least help a lot for most debian-based systems.

We start by firing up a root shell and installing the PostgresSQL server.

ares:~$sudo bash
[sudo] password for f: 
ares:~#whoami
root
ares:~#apt-get install postgresql


It needs a y to install and start the PostgreSQL server and bind it on port 5432 on localhost

Let 's make sure that it started
ares:~#netstat -putan|grep postgres
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      22705/postgres  
tcp6       0      0 ::1:5432                :::*                    LISTEN      22705/postgres  
udp6       0      0 ::1:48884               ::1:48884               ESTABLISHED 22705/postgres


Cool, now we need to login to our PostgreSQL server to reset the postgres user password using the psql --the PostgreSQL interactive terminal.
ares:~#sudo -u postgres psql postgres
could not change directory to "/root"
psql (8.4.8)
Type "help" for help.

postgres=#


To set the password for the user postgres we use the following command
postgres=# \password postgres
Enter new password: 
Enter it again: 
postgres=#


We can list the databases in our PostgreSQL server using the command \l
postgres=# \l
                                    List of databases
   Name    |  Owner   | Encoding |  Collation  |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
                                                             : postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
                                                             : postgres=CTc/postgres
(3 rows)




We can list the users using the command \du
postgres=# \du
            List of roles
 Role name | Attributes  | Member of 
-----------+-------------+-----------
 postgres  | Superuser   | {}
           : Create role   
           : Create DB   




The key sequence Ctrl,d or the command \q exits psql
postgres=# \q
ares:~#


OK, let's add a user and a database to our freshly installed PostgreSQL server.

Let's add a user named pguser0.
ares:~#sudo -u postgres createuser -P pguser0
could not change directory to "/root"
Enter password for new role: 
Enter it again: 
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n
ares:~#


Let's add a database named pgdb0 that belongs to the user pguser0.
ares:~#sudo -u postgres createdb -O pguser0 pgdb0


Let's list all the users and all the databases in our PostgreSQL server.
ares:~#sudo -u postgres psql postgres
could not change directory to "/root"
psql (8.4.8)
Type "help" for help.

postgres=# \du
            List of roles
 Role name | Attributes  | Member of 
-----------+-------------+-----------
 pguser0   |             | {}
 postgres  | Superuser   | {}
           : Create role   
           : Create DB     

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |  Collation  |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 pgdb0     | pguser0  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
                                                             : postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
                                                             : postgres=CTc/postgres
(4 rows)

postgres=# \q
ares:~#


looks good, now lets try to connect to pgdb0 as pguser0.
ares:~#psql pgdb0 -U pguser0 -h localhost
Password for user pguser0: 
psql (8.4.8)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.

pgdb0=>
pgdb0=> \q
ares:~#


it works! , let's configure our PostgreSQL server to listen in 192.168.2.250 by adding it to listen_addresses in
/etc/postgresql/8.4/main/postgresql.conf like
ares:~#grep listen_addresses /etc/postgresql/8.4/main/postgresql.conf
listen_addresses = '192.168.2.250,localhost'            # what IP address(es) to listen on;


Now, we need to restart PostgreSQL
ares:~#/etc/init.d/postgresql-8.4 restart
 * Restarting PostgreSQL 8.4 database server
   ...done.


and make sure it listens where we told him to listen
ares:~#netstat -punta|grep postgre
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      23271/postgres  
tcp        0      0 192.168.2.250:5432      0.0.0.0:*               LISTEN      23271/postgres  
tcp6       0      0 ::1:5432                :::*                    LISTEN      23271/postgres  
udp6       0      0 ::1:50521               ::1:50521               ESTABLISHED 23271/postgres  


OK, the PostgreSQL server listens on 192.168.2.250.

Now, let's allow access to our PostgreSQL server from the network 192.168.2.0/24.

For that, we will have to edit /etc/postgresql/8.4/main/pg_hba.conf
We add the line "host all all 192.168.2.0/24 md5" in the
"# TYPE DATABASE USER CIDR-ADDRESS METHOD" section.


The last 11 lines of /etc/postgresql/8.4/main/pg_hba.conf look like
ares:~#tail -11 /etc/postgresql/8.4/main/pg_hba.conf

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# "local" is for Unix domain socket connections only
local   all         all                               ident
# IPv4 local connections:
host    all         all         127.0.0.1/32          md5
#allow access from 192.168.2.0/24 
host    all         all         192.168.2.0/24        md5
# IPv6 local connections:
host    all         all         ::1/128               md5



OK, let's restart the PostgreSQL server.
ares:~#/etc/init.d/postgresql-8.4 restart
 * Restarting PostgreSQL 8.4 database server
   ...done.


And, attempt to connect to the pgdb0 database from another host in 192.168.2.0/24.
g0:~$psql pgdb0 -U pguser0 -h 192.168.2.250
Password for user pguser0: 
psql (8.4.8)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.

pgdb0=>


It works!

Alternate # and $ in between root and user shell prompts

A tiny bit of bash in the .bashrc does it.

This is a simple version with no colors, showing hostname and working directory before the $ or # symbol.

Let's put the bash bit at the end of our .bashrc
The bash bit
g0:~$cat .bashrc | tail -7

if [ $(whoami) = "root" ];then
        PS1="$(hostname):\\w#"
    else
        PS1="$(hostname):\\w$"
fi


let's put it in root's .bashrc as well
g0:~$sudo bash
g0:~#cat /root/.bashrc |tail -7

if [ $(whoami) = "root" ];then
        PS1="$(hostname):\\w#"
    else
        PS1="$(hostname):\\w$"
fi


cool, now $ denotes a user and # denotes the root user
g0:~#whoami
root
g0:~#exit
exit
g0:~$whoami
g
g0:~$


We can also put it in /etc/skel/.bashrc so every new user from now has it in his .bashrc.

List Perl Modules - Where is Foo.pm?

To list all perl modules in @INC you can use this one liner
n:~$perl -MFile::Find=find -le 'find { wanted => sub {  print $_ if /\.pm\z/ }, no_chdir => 1 }, @INC'

To find out where Foo.pm is located you could use
n:~$perl -MFile::Find=find -le 'find { wanted => sub {  print $_ if /\.pm\z/ }, no_chdir => 1 }, @INC' |grep -i foo

But, I know that you like putting your best modules along with your homebrewed modules in that non standard directory --/usr/scripts/lib/
Then you could do the following to list all your perl modules
n:~$perl -MFile::Find=find -le 'push "/usr/scripts/lib/",@INC; find { wanted => sub {  if($_ =~ /\.pm\z/) { print "$_"; } }, no_chdir => 1 }, @INC' 

And, because I know that you are not going to type all this every time you want to list your modules or find where Foo.pm is let's make the above one liner a bash function or an alias and put it in .bashrc
n:~$head -3 .bashrc
function lspm {
perl -MFile::Find=find -le 'push(@INC,"/usr/scripts/lib/"); find { wanted => sub {  if($_ =~ /\.pm\z/) { print "$_"; } }, no_chdir => 1 }, @INC'
}
n:~$source .bashrc

So, where is Foo.pm?
n:~$lspm | grep -i foo
/usr/share/perl5/Foomatic/Defaults.pm
/usr/share/perl5/Foomatic/UIElem.pm
/usr/share/perl5/Foomatic/PPD.pm
/usr/share/perl5/Foomatic/DB.pm
/usr/scripts/lib/Foo.pm
duh!
And how many modules do I have?
n:~$lspm |wc -l
1503
;)

screen basics

To create a screen named s0 and attach to it use
n:~$screen -S s0

To list all screens use
n:~$screen -ls
There is a screen on:
        2713.s0 (09/14/2011 03:22:05 PM)        (Attached)
1 Socket in /var/run/screen/S-g.

To detach from a screen use the three key sequence Ctrl,a,d
[detached from 2713.s0]
n:~$screen -ls
There is a screen on:
 2713.s0 (09/14/2011 03:22:14 PM) (Detached)
1 Socket in /var/run/screen/S-g.


To reattach to the detached screen s0 use
n:~$screen -r s0

To kill the screen s0 use
n:~$screen -S s0 -X kill
n:~$screen -ls
No Sockets found in /var/run/screen/S-g.

Unrar rar archives in Debian Like Linux Systems



To install unrar

n:~#apt-get install unrar

or

n:~$sudo apt-get install unrar

to unrar

n:~$unrar x archive.rar




The debian debian default is unrar-free. Unfortuanately unrar-free fails often to extract files from archives. You may want to install unrar-nonfree







Install the Net::Telnet module on Ubuntu

Install the Net::Telnet module on Ubuntu and other Debian-based systems.

n:~#sudo apt-get install libnet-telnet-perl

Install the Params::Validate module in Ubuntu 10.04 LTS

Install the Params::Validate module in Ubuntu 10.04 LTS and other Debian-based systems

n:~#sudo apt-get install libparams-validate-perl

Ubuntu - root shell

This is in response to ak who does not like Ubuntu because he does not like to sudo all the time.

ak you will have to find at least a couple of reasons more, because this is so easy to solve.

n:~$sudo bash
[sudo] password for g0: 
n:~#id
uid=0(root) gid=0(root) groups=0(root)
n:~#

or

n:~$sudo -s
[sudo] password for g0: 
n:~#id
uid=0(root) gid=0(root) groups=0(root)
n:~#