A Few Linux Tips and Tricks
Posted by Tyler Muth on April 30, 2008
I feel I’ve neglected the “Linux” aspect of my blog, so here a few tips that I hope you find useful.
What port is the TNS Listener listening on?
sudo netstat -tlnp | grep tns tcp 0 0 0.0.0.0:1521 0.0.0.0:* LISTEN 15481/tnslsnr
I know this is a simple one, but it never hurts to review the basics.
Can I get to a particular port on a remote server?
netcat -w 3 -z -vvn 188.8.131.52 79-81 (UNKNOWN) [184.108.40.206] 81 (?) : Connection timed out (UNKNOWN) [220.127.116.11] 80 (www) open (UNKNOWN) [18.104.22.168] 79 (finger) : Connection timed out
This example is essentially running a port scan on google.com from port 79 to 81, waiting for 3 seconds for a port to time out. You can see that only port 80 is open. I use this constantly when troubleshooting connections between Application Servers and Databases, especially when firewalls are involved. This is much more meaningful than a simple ping. Note that netcat only accepts IP addresses, not host names, so you can ping a host first to get it’s IP address first. Also note that port scans may violate your own network policies and could be construed as a form of hacking, so use at your own risk and tell someone what you’re going to do before you do it. You can install netcat on Windows using Cygwin (the command is nc in cygwin).
Leave a remote session running without using VNC
I discovered the screen command (documented here) about a year ago and I now use it on a regular basis. For example, I did an APEX install on a remote server yesterday. I connected via SSH using PuTTY, typed screen, then started sqlplus and kicked off the install. I then typed ctrl+a d to disconnect from that screen session. I then exited SSH and closed PuTTY. Without screen, that would have killed my install. Since I started the install in a screen session, in continued on in the background. I could then SSH into the machine later in the day and type screen -r to reattach to the session. Trust me, if you use screen for a week, you’ll wonder how you lived without it.
Share the current directory over http
Add the following line to your .bashrc or .bash_profile file:
alias http='python -m SimpleHTTPServer 8000'
Source the file you added it to or logout / login for the change to be reflected. Now navigate to any directory and type webshare. Presto! You can now access that directory from a browser on port 8000.
When I read this tip here, I was simply blown away. It couldn’t be that easy, could it? Yep, it’s that simple and is one of the first aliases I create on a new system.
Sort folders by size
du --max-depth=1 /home/ | sort -n -r
Blink the lights on network card eth0
sudo ethtool -o eth0
Why in the world would you want to do this? Well, I was at a customer site in Pennsylvania last month assisting with (more observing really) a RAC install. Each of the 2 nodes had 9 network cards! This was a demo system shipped in by a hardware vendor, so the cards weren’t even in matching slots for the 2 nodes. We had no idea what card Linux had assigned eth0,1,2… to. I called Sergio Leunissen for a little help and within a few minutes he had the answer. Ethtool will continue to blink the lights on the card until you press ctrl+c, which made it easy for use to map their locations on paper and get the right cables for each network segment in the right card. Thanks Sergio.