Useful Linux commands
Below are a few Linux-related items that can be useful.
One Liners:
General:
- Percentage of memory used:
free -m | grep + | awk '{ a=$3+$4 ; b=($3/a)*100 ; print b "% of " a " MB" }'
Apache:
- Average memory of Apache:
ps aux | grep ^apache | awk '{sum += $6} END {print "Average HTTP RSS: " sum/1024/NR"MB"}'
- Show Apache Processes and cpu/mem status:
echo "Apache Processes: " `ps xuaw |egrep -i '[0-9] /usr/sbin/httpd ' -c` && iostat 2 2 | grep -i ^avg-cpu -A 1|tail -n 2 && free -m
- Kill off all Apache processes that won't die:
for i in `ps aux | grep [h]ttpd | awk '{print $2}'`; do kill -9 $i; done
- List open web connections:
netstat -plnant | grep ":80" | grep -i established
- List and count open web connections:
netstat -plant|grep :80|awk '{print $5}'|cut -d: -f1|sort|uniq -c|sort -n
- List and count open web connections, using the access_log:
sudo cat /var/log/httpd/access_log | tail -2500 | awk '{print $1}' | sort -rn | uniq -c | sort -rn | head -40
- See how many people are hitting a single page at once, good for spotting bad guys:
cat /var/log/httpd/access_log | tail -2500 | grep "GET /profile" | awk '{print $1}' | sort -rn | uniq -c | sort -rn | head -40
- Find out when the apache service was started:
ps axo user,lstart,cmd|awk '!/awk/&&/httpd/{if($1~/root/)print}'
HOME