Skip to content

Instantly share code, notes, and snippets.

@mitio
Last active June 1, 2021 09:27
Show Gist options
  • Save mitio/8536402 to your computer and use it in GitHub Desktop.
Save mitio/8536402 to your computer and use it in GitHub Desktop.
A few tiny shell scripts for quick diagnostics of possible web server problems
#!/bin/sh
grep -E '^Listen ' /etc/apache2/ports.conf | sed 's/:/./' | sed 's/Listen //' | \
ruby -e 'conns = []; while conn = gets; conns << conn.strip; end; system "netstat -an|grep tcp|grep -v LISTEN|grep -E \"\\b#{conns.join "\\b|\\b"}\\b\"";' | awk '{ print $5 }' | ruby -e 'conns = Hash.new(0); while conn = gets; parts = conn.strip.split(":"); ip = parts[0]; port = parts[-1]; conns[ip] += 1; end; conns.sort_by { |ip, count| -count }.each { |ip, count| puts "IP: #{ip.ljust(25)} connections: #{count.to_s.ljust(8)}" } ;nil'
#!/bin/sh
iptables -I INPUT -s $1 -j DROP
sh -c "iptables-save > /etc/network/iptables.save"
#!/bin/sh
netstat -an | grep tcp | grep -v LISTEN | awk '{ print $5 }' | \
ruby -e 'conns = Hash.new(0); while conn = gets; parts = conn.strip.split(":"); ip = parts[0]; port = parts[-1]; conns[ip] += 1; end; conns.sort_by { |ip, count| -count }.each { |ip, count| puts "IP: #{ip.ljust(25)} connections: #{count.to_s.ljust(8)}" } ;nil'
#!/bin/sh
/home/pyfmi/.rbenv/versions/2.0.0-p247/bin/passenger-status --verbose
/home/pyfmi/.rbenv/versions/2.0.0-p247/bin/passenger-memory-stats
#!/bin/sh
netstat='netstat -an'
ps='ps aux'
echo MySQL connections: `$netstat|grep mysql|wc -l`
echo Apache processes: `$ps|grep apache|grep -v grep|wc -l`
echo TCP connections: `$netstat|grep tcp|wc -l`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment