1.4.1. shell实例

把数据备份并发送到指定的email下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/sh

cd /data/backup/mysql;
Folder=backup_`date "+%y%m%d-%H%M"`;
mkdir $Folder;
cd $Folder;
mysqldump -uadmin -pq1w2e3r4 --database wordpress > blog.sql;
mysqldump -uadmin -pq1w2e3r4 --database ultrax > bbs.sql;
mysqldump -uadmin -pq1w2e3r4 --database wprelay > relay.sql;
mysqldump -uadmin -pq1w2e3r4 --database wpfinancial > finance.sql;
mysqldump -uadmin -pq1w2e3r4 --database wpdiary > diary.sql;
mysqldump -uadmin -pq1w2e3r4 --database wplele > lele.sql;
cd ..;
tar zcf $Folder.tar.gz $Folder;
rm -rf $Folder;

/usr/local/bin/sendEmail -f gordonsendmail@163.com \
    -t xinxishangwang@163.com \
    -s smtp.163.com \
    -xu gordonsendmail@163.com \
    -xp q1w2e3r4 \
    -l ./sendmail.log \
    -o message-charset=utf-8 \
    -u "[数据库备份]$Folder" \
    -m "备份数据" \
    -o timeout=500 \
    -a ./$Folder.tar.gz \
    -o tls=yes;

实例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh
#============说明===============
# 此脚本是用于解决多个系统环境配置文件不同的问题
#==============================

usage() {
  echo "-----------------用法-----------------------"
  echo "参数1: octopus结点名"
  echo "参数2: app, pvt, dev, pr。分别代表4个环境."
  echo "其他:"
  echo "\t1.配置文件会使用config/pr_octopus.config"
  echo "\t2.会生成start.sh文件,可直接执行"
  echo "-----------------实例-----------------------"
  echo "sh> ./gen_start.sh octopus@10.140.2.17 pr"
  echo "-----------------end-----------------------"
}

if test -z $1 | test -z $2; then
  usage
  exit
fi

if !(test $2 = "app" || test $2 = "pvt" || test $2 = "dev" || test $2 = "pr"); then
    usage
    exit
fi


cat gen_start.tpl | sed "s/{{NAME}}/$1/g" | sed "s/{{CONFIG}}/$2/g" > start.sh
chmod +x start.sh