Skip to content

Instantly share code, notes, and snippets.

@shichao-an
shichao-an / instance.py
Created October 18, 2014 20:56
Get EC2 instance type
#!/usr/bin/env python
# Get CPU (core number) and memory by instance_type
# usage: python instance.py (INSANCE_TYPE|VCPU MEMORY)
import json
import sys
import urllib2
JSON_URL = 'https://raw.githubusercontent.com/powdahound/ec2instances.info/master/www/instances.json'
@shichao-an
shichao-an / 115wangpan-up.py
Last active August 29, 2015 14:08
Utility script for 115wangpan
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 expandtab softtabstop=4 smarttab textwidth=78
#
# Upload a torrent file and create a BitTorrent task
# Usage: python 115wangpan-up.py TORRENT_FILE
from __future__ import print_function
import sys
from u115 import API
@shichao-an
shichao-an / check_upstream_timeout.sh
Created November 14, 2014 22:21
NRPE plugin script to check Nginx proxy_pass upstream timeout error
#!/bin/bash
# This script checks nginx error log for "upstream timed out" events
# Update $last_num variable to the latest error number after you fixed the issue
last_num=75305
log_file=/var/log/nginx/error.log
[ -f "$log_file" ] || { echo "WARNING - error log does not exist: $log_file"; exit 1; }
current_num=$(grep 'upstream timed out' "$log_file" | tail -1 | awk ' { print $5 }' | tr -d '*')
# If $current_num is not empty string and larger than $last_num, then we get an error
[ -n "$current_num" ] && [ "$current_num" -gt $last_num ] && \
@shichao-an
shichao-an / install_nrpe.sh
Created November 21, 2014 22:02
Install NRPE on Ubuntu
apt-get install nagios-nrpe-server nagios-plugins
@shichao-an
shichao-an / openssl_keygen.sh
Created November 27, 2014 01:07
OpenSSL generate key into the same output file
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.key
@shichao-an
shichao-an / upgrade_php.sh
Created December 3, 2014 01:48
Upgrade PHP 5.3 to 5.5 on RHEL6
#!/bin/sh
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
yum install -y yum-plugin-replace
yum replace -y php-common --replace-with=php55w-common
@shichao-an
shichao-an / add_public_key.sh
Last active August 29, 2015 14:11
Add SSH public key
#!/bin/bash
# Usage:
# First, source this script:
# $ source add_public_key.sh
# Then, use the function add user:
# $ add_public_key john 'ssh-rsa very-long-hash'
add_public_key()
{
@shichao-an
shichao-an / vpnsetup.sh
Last active August 29, 2015 14:11 — forked from hwdsl2/.MOVED.md
#!/bin/sh
#
# Amazon EC2 user-data file for automatic configuration of IPsec/L2TP VPN
# on a Ubuntu server instance. Tested with 14.04 (Trusty) AND 12.04 (Precise).
# With minor modifications, this script *can also be used* on dedicated servers
# or any KVM- or XEN-based Virtual Private Server (VPS) from other providers.
#
# DO NOT RUN THIS SCRIPT ON YOUR PC OR MAC! THIS IS MEANT TO BE RUN WHEN
# YOUR AMAZON EC2 INSTANCE STARTS!
#
#!/bin/bash
#
# Author : N.Hashimoto
# E-mail : mrhashnao@gmail.com
# Description : Verify node joining cassandra multinode cluster, and
# send alert if the number of live node is less than the specified number.
#
# ------------------------------------------------------------
# functions
# ------------------------------------------------------------
#!/bin/bash
# Setup Nagios NRPE on Amazon EC2 (Ubuntu)
apt-get update
apt-get install -y nagios-nrpe-server nagios-plugins
sleep 2
mkdir -p /etc/nagios
cat > /etc/nagios/nrpe_local.cfg <<EOF