Skip to content

Instantly share code, notes, and snippets.

View koy1619's full-sized avatar
🎯
Focusing

Chris koy1619

🎯
Focusing
View GitHub Profile
@koy1619
koy1619 / nginx-vhost.conf
Created April 2, 2014 07:36
nginx-vhost.conf
server {
listen 8080;
server_name test.com;
index index.html index.htm index.php;
root /home/wwwroot/test;
location /test2 {
auth_basic "pd";
auth_basic_user_file /usr/local/nginx/conf/vhost/pd.passwd;
allow 114.112.113.111;
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
#!/bin/bash
wget http://nodejs.org/dist/v0.10.28/node-v0.10.28-linux-x64.tar.gz
tar xzf node-v0.10.28-linux-x64.tar.gz
mv node-v0.10.28-linux-x64 /usr/local/
echo "PATH=$PATH:/usr/local/node-v0.10.28-linux-x64/bin" >> /etc/profile
echo "export PATH" >> /etc/profile
source /etc/profile
cp /usr/local/node-v0.10.28-linux-x64/bin/node /usr/bin
cp /usr/local/node-v0.10.28-linux-x64/bin/npm /usr/bin
@koy1619
koy1619 / row.sh
Last active August 29, 2015 14:10
mysql查询日志切割脚本
#!/bin/bash
NOW=$(date +"%Y.%m.%d")
cd /tmp
tar zcvf /backup/$NOW-row.tar.gz row.log
:>row.log
#find ${BACKUP_DST} -ctime +30 | xargs rm -rf
@koy1619
koy1619 / add_swap.sh
Created July 1, 2015 02:23
add_swap.sh
#!/bin/bash
#########################################
#Function: add a new swap partition
#Usage: bash add_swap.sh
#Author: Customer service department
#Company: Alibaba Cloud Computing
#Version: 2.1
#########################################
check_os_release()
@koy1619
koy1619 / Denyhosts.sh
Last active October 13, 2015 03:46
Denyhosts.sh
#!/bin/bash
#Denyhosts SHELL SCRIPT
cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"=" $1;}' >/home/sh/Denyhosts.txt
DEFINE="10"
for i in `cat /home/sh/Denyhosts.txt`
do
IP=`echo $i|awk -F= '{print $1}'`
NUM=`echo $i|awk -F= '{print $2}'`
if [ $NUM -gt $DEFINE ]
@koy1619
koy1619 / ntp.conf
Last active October 27, 2015 03:07
ntp.conf
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
# 允许本地所有操作
restrict 127.0.0.1
restrict -6 ::1
# 允许的局域网络段或单独ip
#restrict 127.0.0.1   
#restrict 192.168.10.2  # 指定某台机器时间同步
@koy1619
koy1619 / mysql_master_slave_monitor.sh
Last active December 17, 2015 12:39
mysql服务&主从监控脚本 将此脚本放于mysql从库上,设置crontab -e */10 * * * * root /bin/sh /home/mysqld_monitor.sh 每十分钟跑一次,检测到mysqld服务或者是主从宕掉之后会发送邮件(只发一次)!
#!/bin/bash
mysql_status=`netstat -nl | awk 'NR>2{if ($4 ~ /.*:3306/) {print "Yes";exit 0}}'`
PortNum=`netstat -lnt|grep 3306|wc -l`
if [ "$mysql_status" == "Yes" ];then
slave_status=`mysql -uroot -p123456 -e"show slave status\G" | grep "Running" | awk '{if ($2 != "Yes") {print "No";exit 1}}'`
if [ "$slave_status" == "No" ];then
echo "slave is not working!"
[ ! -f "/tmp/slave" ] && echo "Slave is not working!" | mail -s "Warn!MySQL Slave is not working" monitor@test.me
@koy1619
koy1619 / DropboxBackup.sh
Last active December 17, 2015 12:39
参考http://davehope.co.uk/Blog/backup-your-linux-vps-to-dropbox/ 备份数据到Dropbox,可能因为中国大陆网络环境受影响
#!/bin/bash
DROPBOX_USER="xxx@xxx.com" //Dropbox的账号
DROPBOX_PASS="12345678" //Dropbox的密码
DROPBOX_DIR="/backups" //Dropbox中的文件夹名称
BACKUP_SRC="/home/wwwroot /data" //需要备份的文件夹路径,可以同时指定多个中间用空格隔开
BACKUP_DST="/home/backup" //用来存放备份的文件夹路径
MYSQL_SERVER="127.0.0.1" //连接本地MySQL
MYSQL_USER="root" //本地MySQL的用户
MYSQL_PASS="12345678" //本地MySQL的密码
@koy1619
koy1619 / dnspodsh.sh
Created May 20, 2013 08:51
在bash中使用DNSPod的API接口实现DDNS客户端
#!/bin/bash
##############################
# dnspodsh v0.3
# 基于dnspod api构架的bash ddns客户端
# 作者:zrong(zengrong.net)
# 详细介绍:http://zengrong.net/post/1524.htm
# 创建日期:2012-02-13
# 更新日期:2012-03-11
##############################