One Liners
Here is a collection of oneliners that I’ve either come up with myself or gathered from the cobs of the web. Feel free to use them and abuse them, I hope they help.
This little diddy is for pulling certain status codes out of Apache log files (combined format). The example above will list all of the 3xx (redirect) codes that your server spit out since the files were rotated. Altering the 3\d\d to 404 will only list the 404’s that the script kiddies couldn’t find.
grep -P '^([\d]{1,}\.){3}([\d]{1,}) - - \[.*\] \"\S* \S* \S*\" 3\d\d [\d]{1,}.*' filename
This is actually pretty stupid, but I like my fstab formatted nicely. Run this, redirect the output to /etc/fstab (you made a backup of course) and you have a nicely formatted /etc/fstab.
awk '{ printf("%-20s\t%-40s\t%-10s\t%-30s\t%s %s\n", $1, $2, $3, $4, $5, $6) }' /etc/mtab
Top talkers – this one liner lists the top talkers from apache access log files.
grep 'date' access_log | awk '{ print $1 }' | sort | uniq -c | sort -rn
Strace top cpu process.
top -b | head -20 | grep PID -A 1 | grep -v PID | awk '{ print $1 }' | xargs strace -p
Total bytes transferred in an Apache access log
awk '{ sum +=$10 } END { print sum }' logfile
This is how you monitor a node of an RHCS
watch -n 1 'clustat && echo '' && echo '====================== CLM ======================' && tail -n 100 /var/log/messages | grep CLM | tail -n 5 && echo '' && echo '===================== TOTEM =====================' && tail -n 100 /var/log/messages | grep TOTEM | tail -n 5 && echo '' && echo '====================== CPG ======================' && tail -n 100 /var/log/messages | grep CPG | tail -n 5 && echo '' && echo '====================== CMAN =====================' && tail -n 100 /var/log/messages | grep CMAN | tail -n 5 && echo '' && echo '====================== SYNC =====================' && tail -n 100 /var/log/messages | grep SYNC | tail -n 5 && echo '' && echo '===================== fenced ====================' && tail -n 100 /var/log/messages | grep fenced | tail -n 5 && echo '' && echo '==================== clurmgrd ===================' && tail -n 100 /var/log/messages | grep clurmgrd | tail -n 5'
Numerically sorted human readable directory usage
du -x --max-depth=1 | sort -n | awk '{ print $2 }' | xargs du -hx --max-depth=0