Tuesday, March 9, 2010

Some slick Unix/Linux commands... much more powerful and useful

KILL

usage:

Kill process by Process ID

  • kill -9 [PID] --> Forcefully Kill
  • kill -15 [PID] --> Gracefully Kill
  • kill %[JobID] --> JobID can be checked by command #jobs

Kill process by Process Name

  • killall [proces name]

PID/Process name can be found using commands like

  • ps -aux
  • ps -elf
  • netstat -anp
  • lsof -w -n -i [tcp/udp:port number]

System Tuning Commands:

#mpstat -A ALL --> CPUs status

#top --> Press 'I' to toggle between Irix Mode (Irix Mode display resource usage mulitplied by total number of CPUs) ; Press "1" to see all the CPUs

# sar

Networking Commands

#netstat -anp --> Where 'p' flag shows which program is making connection

[ Hey, now I know which program is making a connection, can I use kill command to kill by process name or PID? Answer: Ofcourse, that's the reason I am writing this article ]

Now you know how to terminate the particular remote connection in the server. There is also another technique using #lsof.

# lsof -w -n -i tcp:22

This command will display all the SSH (tcp:22) connections. So, you can see who has intruded in your system using SSH. This will also give process ID (PID) or process name, which you can terminate using KILL command.

[ use man page for each command in details]

#ifstat

#ethtool [ethernet interface name] --> this command can used to see if the interface is physically down or not

e.g # ethtool eth1

#netstat -i

#netstat -s


To get the BIOS information

#dmidecode

To list the hardware

#hwinfo

or

#lshw

[Note: lshw is not the linux project. If you want to use lshw, you have to download and install the RPM for that command http://ezix.org/project/wiki/HardwareLiSter ]


Bash Script to collect system information:

This is one of the simple script file to pull basic and informative information about your server:


#********************

#ServerReport.sh

# Created by DShah

# Please use it at your own risk

#********************

#!/bin/bash
miniDivider(){

echo "*******************************************************************";
}

serverInfo() {

uname -a
cat /etc/*release

}

diskInfo() {

# fdisk -l
df -h
iostat

}

memoryInfo() {

free -m
vmstat

}

cpuInfo() {

mpstat
mpstat -P ALL

}

overallInfo() {

top -b -n2


}

networkInfo() {
netstat -s
miniDivider

sleep 2
netstat -s
}

dividerLine(){

echo "########################################################################";

echo "########################################################################";

}

fileName="serverReporting.txt"

rm $fileName
touch $fileName

echo "ServerInfo Reporting"
serverInfo >> $fileName
dividerLine >> $fileName

echo "DiskInfo Reporting"
diskInfo >> $fileName
dividerLine >> $fileName

echo "MemoryInfo Reporting"
memoryInfo >> $fileName
dividerLine >> $fileName

echo "CPUInfo Reporting"
cpuInfo >> $fileName
dividerLine >> $fileName

echo "Network Info Reporting"
networkInfo >> $fileName
dividerLine >> $fileName

echo "Top command reporting";
overallInfo >> $fileName


1 comment:

Devendra said...

Really handy info on SLES10

http://www.softpanorama.org/Commercial_linuxes/Suse/index.shtml