Linux – Tweaks

Tweak 1:

Find all zombie process on server(Run this as a root)
ps aux | awk ‘{ print $8 ” ” $2 ” ” $11}’ | grep -w Z

Kill the zombie process (be careful before run this since it would kill the parent process which is related to the zombie processes.)
You cannot kill zombies, as they are already dead. But if you have too many zombies then kill parent process or restart service.

ps aux | awk ‘{ print $8 ” ” $2 ” ” $11}’ | grep -w Z |awk ‘{print $2}’|xargs kill -9

OR

You can kill zombie process using PID obtained from the above command. For example kill zombie proces having PID 4104:

# kill -9 4104

Please note that kill -9 does not guarantee to kill a zombie process.

***************************************************************************************************************

Tweak 2:

Run the following command on your server.

python -m SimpleHTTPServer

Allow the Port 8000 in your firewall(If required)

Open the following Url via the browser.
http://Server IP:8000/

You will get the current directory tree page of the server.

***************************************************************************************************************

Tweak 3:

ssh -N -L2001:localhost:80 somemachine

start a tunnel from some machine’s port 80 to your local post 2001

now you can acces the website by going to http://localhost:2001/

***************************************************************************************************************

Tweak 4:
Salvage a borked terminal
Command : reset

If you bork your terminal by sending binary data to STDOUT or similar, you can get your terminal back using this command rather than killing and restarting the session. Note that you often won’t be able to see the characters as you type them

***************************************************************************************************************

Tweak 5:
Empty a file

> file name

OR

echo > filename
For when you want to flush all content from a file without removing it (hat-tip to Marc Kilgus).

***************************************************************************************************************

Tweak 6:
Ping with traceroute:

mtr google.com

mtr, better than traceroute and ping combined

mtr combines the functionality of the traceroute and ping programs in a single network diagnostic tool.

As mtr starts, it investigates the network connection between the host mtr runs on and HOSTNAME. by sending packets with purposly low TTLs. It continues to send packets with low TTL, noting the response time of the intervening routers. This allows mtr to print the response percentage and response times of the internet route to HOSTNAME. A sudden increase in packetloss or response time is often an indication of a bad (or simply over‐loaded) link.

***************************************************************************************************************

Tweak 7:

find all active IP addresses in a network

nmap -sP 192.168.0.*

There are several other options. This one is plain and simple.

Another option is:

nmap -sP 192.168.0.0/24

***************************************************************************************************************

Tweak 8:

How to find out the server reboot/shutdown count?

last | grep -i “^reboot” | wc -l

This command will show only the count of the server reboots (but this will
not include the server shutdown)
Ex:
last | grep -i “^reboot”|wc -l


last | grep -i “^reboot”

reboot system boot 2.6.18-128.1.10. Sun May 31 20:10 (00:34)
reboot system boot 2.6.18-128.1.10. Sun May 31 20:05 (00:03)

tune2fs -l /dev/hda1|grep -i mount|grep -v Maximum
This will show you the details of the server how many times mounted
(including server down/shutdown/reboot)
Note: /dev/hda1 denotes /boot partition of the server

Ex:
tune2fs -l /dev/hda1|grep -i mount|grep -v Maximum
Last mounted on: <not available>
Default mount options: user_xattr acl
Last mount time: Sun May 31 20:10:57 2009 -> last
rebooted/mount time of the /boot partion
Mount count: 6 -> Total server shutdown/reboot count

***************************************************************************************************************

Tweak 9:

How to change Mac address(virtually) on Linux box?

Log into the system as root(Superuser)

# ssh root@IP(host)

shutdown the interface

# ifdown eth0

Then execute the following command

# ifconfig eth0 hw ether 00:05:6f:62:ea:b3

start the interface

# ifup eth0
Now your system will use the above given mac address as your h/w address of your NIC
Have a nice day folks…!
***************************************************************************************************************
Written by actsupp-r0cks