标签归档:bash

实现mysql自动备份的简单脚本

#!/bin/bash
#chmod 700 backup.sh
#crontab -e
#每天4点, mysql备份数据
#0 4 * * * /home/cron/mysql_backup.sh

host="localhost"
user="dbname"
password="dbname"
db_name="dbname"

#backup directory
base_dir="/home/backup"
backup_log="${base_dir}/mysql_backup.log"
backup_path=${base_dir}

#file info
date=$(date +"%Y-%m-%d")
filename=$backup_path/$db_name-$date.sql.gz

#back up
mkdir -p $backup_path
mysqldump --user=$user --password=$password --host=$host $db_name | gzip > $filename
#Delete files older than 10 days
find $backup_path/* -mtime +10 -exec rm {} \;
echo "backup finished at $(date +'%Y-%m-%d %H:%M:%S')" >> "$backup_log"

linux 下使用科学上网

目前稳定可用的科学上网服务

加速度:注册后可申请2元试用,可同时使用2条线路,24小时不满意退款。

使用方法

方法1:命令行

apt 安装

sudo apt-get install shadowsocks

pip 安装

sudo apt-get update
sudo apt-get install python-pip
sudo apt-get install python-setuptools m2crypto
pip install shadowsocks

继续阅读

ubuntu中创建程序为自启动

#!/bin/bash
### BEGIN INIT INFO
# Provides:          appname
# Required-Start:    remote_fs syslog
# Required-Stop:     remote_fs syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: appinfo
# Description:       appinfo
### END INIT INFO

bin="/home/user/app"

start(){
  ps -ef | grep bin | grep -v grep > /dev/null   if [ ? -eq 0 ]; then
    echo "The Service has started."
  else
    echo -n "Starting..."
    bin 1>/dev/null 2>/dev/null &     echo "Done!"   fi }  stop(){   ps -ef | grep bin | grep -v grep > /dev/null
  if [ ? -eq 0 ]; then     echo -n "Stoping..."     killall bin
    echo "Done!"
  else
    echo "The service did not start."
  fi
}

case 1 in start)   start ;; stop)   stop ;; status)   ps -ef | grep bin | grep -v grep > /dev/null
  if [ ? -eq 0 ]; then     echo "The service is running."   else     echo "The service is not running."   fi ;; *)   echo "Usage: 0 {start|stop|status}"
;;
esac

脚本放在 /etc/init.d/ 目录下,添加 执行 权限。

# 添加到服务
sudo systemctl enable app  # app 是服务文件名
# 启动服务
sudo service app start

继续阅读