Skip to content

Instantly share code, notes, and snippets.

@shichao-an
shichao-an / 115wangpan-dl.py
Last active August 29, 2015 14:06
Utility script for 115wangpan
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 expandtab softtabstop=4 smarttab textwidth=78
from __future__ import print_function
import os
import sys
from u115 import API, File, Directory
ARGV = sys.argv
GLOB_ALL = False
wget -qO - https://gist.githubusercontent.com/shichao-an/c55ba272567b44f50fb6/raw/2edec4ad9b090d78c9690c245dfe0493a7d9f8aa/wb.sh | bash
@shichao-an
shichao-an / set-hostname.sh
Last active August 29, 2015 14:07
Set hostname on Ubuntu
#!/bin/bash
# Set hostname on Ubuntu 12.04 and 14.04
usage='Usage: set-hostname.sh HOSTNAME'
[ $# -ne 1 ] && { echo "$usage" >&2; exit 1; }
echo 'Updating hostname...'
if which hostnamectl > /dev/null
then
# Ubuntu 14.04 that ships with hostnamectl
@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 / build_mysql.sh
Last active January 22, 2023 16:05
Build and install MySQL 5.1 from source on Ubuntu 14.04
#!/bin/bash
# Run as root
set -e
apt-get update
apt-get install -y build-essential
apt-get install -y libncurses5-dev
useradd mysql