April 17

One-liners

I’ll be posting bash one-liners here for my own reference and for you! Each item on the list ranges in value from useful to rarely needed, but important to have.

Set an audible alert when a server comes back online:

ping -i 2 -a IP

The ICMP packets on the server go bonk..bonk..bonk! — The -a or (audible) option to ping can be quite valuable when you need to step away from your desk or if you have a million other things going on that require your attention. Option -i sets the interval in seconds between each ping.


Highlight all grep matches in red:

grep -i --color=auto


List the top 20 IPs connecting to a website:

tail -10000 /usr/local/apache/domlogs/populardomain.com | awk {'print $1'} | sort | uniq -c | sort -nr | head -n 20

This will look at the last 10,000 lines of /usr/local/apache/domlogs/populardomain.com, grab the first row (IP address) and then perform a sorted count of the unique IP addresses making requests to the domain whose logfile you are examining. –Great for finding single source DoS or small-scale DDoS attacks on a particular VirtualHost.



Quickly compute the amount of memory virtual machines are using in Xen:

xm list | awk {'print $3'} | grep ^[0-9] | awk '{s+=$1} END {print s}'



Quickly compute the amount of CPU all virtual machines are using in Xen:

xentop -b -i 2 | grep -v 0.0 | awk {'print $4'} | grep -v ^CPU | tail -n +2 | awk '{s+=$1} END {print s}'



Fix Apache – No space left on device: Couldn’t create accept lock or Cannot create SSLMutex:

for i in `ipcs -s | awk '/httpd/ {print $2}'`; do (ipcrm -s $i); done

Leave a Comment

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>