UNIX
See a list of current connections to your web server
by ichilton on Dec.02, 2009, under UNIX
If you have a high load on your web server, it’s useful to be able to see a list of the current connections on port 80 as sometimes high load can be caused by someone abusing the site - for example scraping it or some kind of denial of service attack.
This code will show a list of the ip’s currently connected to your server on port 80 with a count of the number of connections to the left of it. It’s ordered by the number of connections - highest first:
netstat -ntulpa | grep :80 | awk '{print $5}' | cut -d: -f1 | sort -n | uniq -c | sort -n -r
Find and Replace Across Multiple Files
by ichilton on Mar.15, 2009, under UNIX
Have you ever needed to change the same thing in a load of files and have had to sit there and go through each one in turn and make the same change?
This is a really useful and simple command:
perl -pi -w -e 's/from text/to text/g;' *
It simply goes through all files matching * and runs the regular expression, ’s/from text/to text/g’ - which means replace all instances of “from text” with “to text”. nifty!