Daily tools

Basic diagnosis commands in solaris and in linux

1. To check icmp request

ping -s hostname (Solaris)

2. To view load, cpu usage and memory usage

top and press M (Linux)

prstat or prstat -a or prstat -p <pid> -L (Solaris)

prstat -m

to access microstate accounting information

To sort the output by CPU usage and to restrict the output to the top five processes
prstat -s cpu -n 5

Adding the -a option to any prstat command will identify how many processes each user is using, what percent of the CPUs, and how much memory, they are using on a system.
prstat -s cpu -a -n 5

There are more utility too
sar
sar -P ALL ( stat of each core )
sar -r ( Memory and swap stat )
sar -q -s (start time) -e ( end time)
sar -n DEV | EDEV ( Interface stat)
mpstat 5 5 (Soalris) mpstat -P ALL (Linux)

ps -eo pcpu,pid,user,args| grep process | sort -r -k1

This shows a list of the processes taking up cpu time in the format %cpu PID user command
/usr/ucb/ps -aux | awk ‘{print $3,$2,$1,$11}’ |grep -v 0.0

Another way to get a clear stat of system memory usage –

echo ::memstat | mdb -k ( run this as root user. It will take time depending on processing power)

3. To view size of physical memory

free -m

prtconf -pv | grep Memory

4. To view cpu information

more /proc/cpuinfo

psrinfo

5. To view info about particular port or open session on a port or routing table

netstat -ntpl [linux]

netstat -f inet -an|grep LISTEN [view the list of port open on the host]

netstat -an| grep ‘ESTABLISHED’ [view different conn established on different port]

netstat -an| grep ‘ESTABLISHED’| grep ‘ip.port’ [same as above]

netstat -nr [view routing table]

6. To check wheter port is alive or not

telnet ip port

7. To compress or uncompess a file

gzip filename

gunzip -c file.gz| tar xvf –

tar zxf file.tar.gz or gtar zxf file.tar.gz

8. To determine route of a request

traceroute <ip or hostname>

9. To view a particular process is running or not and its argument

ps -ef | grep process

pargs <PID>

10. Remove or replace with find

find . -name ".mp3" -exec rm -f {} \; [find the .mp3 file and then remove them]

find ./ -name ‘*.clm’ -exec mv {} {}\.txt \; [find all .clm file & then move all to .txt]

11. Matching pattern using grep

grep abc /etc/passwd [match whether ‘abc’ exists or not]

grep -R -l ‘clamav’ /usr/share/doc [List the file names of all files that contains clamav under /usr/share/doc ]
grep “2008-07-17\ 13:[1-5][0-9]:[0-5][0-9]” [Matching lines using regular expression]

12. Text formatting

   delete trailing whitespace (spaces, tabs) from end of each line

   sed 's/[ \t]*$//'                    

   delete BOTH leading and trailing whitespace from each line

   sed 's/^[ \t]*//;s/[ \t]*$//

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s