More snippets

Yesterday I posted about having an existing ssh-agent load on all new shells. Here are two more handy snippets of code from my .bash_profile

The first code snippet is a follow on from yesterday, were I can type ‘lock’ or ‘unlock’ into my shell and the ssh-agent will follow on accordingly. When your ssh-agent is locked, users that have access to the ssh-agent will be required to type in your SSH agent password.

function lock () { ssh-add -x }
function unlock () { ssh-add -X }

The next snippet of code adds a ‘ns’ command. I have issues trying to remember IPs – especially when they are not used too often. This command lets me easily remember 🙂

alias ns='for x in ns1 ns2 ns3 ns4 ; do host $x.google.com; done'

When run:

[tim@2-xlc-controller ~]$ ns
ns1.google.com has address 216.239.32.10
ns2.google.com has address 216.239.34.10
ns3.google.com has address 216.239.36.10
ns4.google.com has address 216.239.38.10

The last dirty one liner that I love is another simple time saver. Many people use the ‘whois‘ command to find out what nameservers are used by a domain name. It’s not too long before you work out that it is not really the best way to be finding out what the domain name’s nameservers are.

function nameservers() { echo $1\'s nameservers are:; dig +trace $1 | grep NS  | grep "^$1.";  }

This handy one liner allows me to do awesome things like:

[tim@3-xlc-controller ~]$ nameservers google.com
google.com's nameservers are:
google.com.             172800  IN      NS      ns2.google.com.
google.com.             172800  IN      NS      ns1.google.com.
google.com.             172800  IN      NS      ns3.google.com.
google.com.             172800  IN      NS      ns4.google.com.

Leave a Comment

Your email address will not be published. Required fields are marked *