Skip to content

Instantly share code, notes, and snippets.

View fduran's full-sized avatar

Fernando Duran fduran

View GitHub Profile
@fduran
fduran / gist:1870554
Created February 20, 2012 18:34
Linux disk/memory stress test
# www.fduran.com
# hardware stress test
# mismatched md5sums shows a faulty disk/RAM
# time depends on hardware, ex: 1 sec per 100 count
dd if=/dev/zero of=/tmp/test.file bs=1M count=1000
for i in {1..5}; do md5sum /tmp/test.file; done
@fduran
fduran / gist:1947100
Created March 1, 2012 03:40
Apache security: installing mod_security
# www.fduran.com
# installing mod_security http://www.modsecurity.org (Debian-based distro)
# apachectl -M
apache2: Could not reliably determine the server's fully qualified domain name, using boxmetric.com for ServerName
Loaded Modules:
core_module (static)
log_config_module (static)
logio_module (static)
mpm_prefork_module (static)
@fduran
fduran / gist:1989361
Created March 6, 2012 22:16
Find Linux users that can log in with password
# www.fduran.com
# Check which Linux users could log in with password, see "man shadow" for the second field in the /etc/shadow file:
# "If the password field contains some string that is not a valid result of crypt(3), for instance ! or *, the user will not be able to use a unix password to log in (but the user may log in the system by other means).
# this awk one-liner will find users that have common used * or ! in the password field or field starts with ! (locked account). It's possible that still found user cannot log in due to other non-crypt character in the field
awk -F: '$2 != "*" && $2 !~ /^!/ { print $1, " can log in" }' /etc/shadow
@fduran
fduran / CloudFlareAlwaysOnline.html
Created October 24, 2012 22:18
CloudFlare Always Online
<h1>CloudFlare Always Online</h1>
<b>Summary:</b> I'd like to know if CloudFlare's <a href="http://www.cloudflare.com/always-online">Always Online</a> works when a web server goes completely down (server unresponsive).
1) According to CloudFlare's web site, the answer seems to be "yes" (emphasis mine):
<ul>
<li><a href="http://www.cloudflare.com/always-online">Description of the service</a>: Always Online is a feature that caches a static version of your pages in case your <b>server goes offline</b>.</li>
<li><a ref="http://blog.cloudflare.com/always-online-because-downtime-sucks">Blog entry</a>: "If, for any reason, your web host or service provider <b>goes down</b>, we kick in to keep your site online"</li>
<li><a href="https://cloudflare.tenderapp.com/kb/troubleshooting/why-doesnt-always-online-display-all-pages-of-my-site-when-my-server-is-down">KB documentation</a>: on the point 7: "In order to trigger Always Online, your web server will need to be <b>completely unresponsive</b>, or ..."</li>
<li>In a
@fduran
fduran / gist:4271952
Created December 12, 2012 21:49
Linux find files opened for writing
# www.fduran.com
# files opened for writing
lsof | grep -e "[[:digit:]]\+w"
@fduran
fduran / gist:4271967
Created December 12, 2012 21:52
Apache Redirect Subdomain to port
# www.fduran.com
# redirect from apache port (:8080 for ex for tomcat etc) to subdomain
# in apache config:
<VirtualHost *:80>
ServerName subdomain.example.com
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
@fduran
fduran / gist:4271982
Created December 12, 2012 21:54
Apache2 optimization
# www.fduran.com
# Apache2 optimization
# apache-wide (/etc/apache2/apache2.config ):
# compression
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
@fduran
fduran / gist:4514042
Created January 11, 2013 21:18
Linux "Too many files open" error
# www.fduran.com
# Linux "Too many files open" error
# check current number of open files:
lsof |wc -l
# check maximum number of file descriptors
sysctl -a |grep file-max
# increment value: edit
@fduran
fduran / gist:4543001
Last active May 9, 2018 18:35
Python script to test/monitor if a Django site using authentication is up
# www.fduran.com
# python script to test/monitor if a Django site using authentication is up
# with logging output to a file including response times
# use in cronjob and output to log file, for ex: python /path/to/script.py >> /var/log/webmonitor.log
# bash: install pip if not already in system
apt-get install python-setuptools python-dev build-essential
easy_install -U pip
# bash: install requests
@fduran
fduran / gist:4586880
Created January 21, 2013 15:35
Create Java KeyStore from SSL certificate
# www.fduran.com
# Create Java KeyStore from SSL certificate for domain example.com
# Change format from cert.crt PEM (----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----) to DER
openssl x509 -in cert.crt -inform PEM -out cert.der -outform DER
# create KeyStore cert.jks for your domain ("alias" in keytool, "common name" or CN in openssl req)
keytool -import -trustcacerts -alias example.com -file cert.der -keystore cert.jks