shell編程實戰21

1. 併發備份數據庫mysql

#!/bin/bashsql

exec &> /tmp/mysql_bak.log數據庫

if ! which innobackupex &>/dev/nll
then
echo "安裝xtrabackup工具"
rpm -ivh http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm && \
yum install -y percona-xtrabackup-24
if [ $? -ne 0 ]
then
echo "安裝xtrabackup工具出錯,請檢查。"
exit 1
fi
fibash

bakdir=/data/backup/mysql
bakuser=vyNctM
bakpass=99omeaBHh併發

function bak_data {
db_name=$1
db_host=$2
db_port=$3
cnf=$4
[ -d $bakdir/$db_name ] || mkdir -p $bakdir/$db_name
innobackupex --defaults-file=$4 --host=$2 --port=$3 --user=$bakuser --password=$bakpass $bakdir/$1
if [ $? -ne 0 ]
then
echo "備份數據庫$1出現問題。"
fi
}工具

fifofile=/tmp/$$ ## 這個腳本運行的pid
mkfifo $fifofile
exec 1000<>$fifofile3d

thread=10
for ((i=0;i<$thread;i++))
do
echo >&1000
doneblog

cat /tmp/databases.list | while read line
do
read -u1000
{
bak_data `echo $line`
echo >&1000
} &
done字符串

wait
exec 1000>&-
rm -f $fifofileinput

2. 打印三角形

 

3. 截取字符串

 

4. 修改文本格式

 

5. 自定義rm

#!/bin/bash

filename=$1

if [ ! -e $1 ]
then
echo "$1 不存在,請使用絕對路徑"
exit
fi

d=`date +%Y%m%d%H%M`
f_size=`du -sk $1|awk '{print $1}'`
disk_size=`LANG=en; df -k |grep -vi filesystem|awk '{print $4}' |sort -n |tail -n1`
big_filesystem=`LANG=en; df -k |grep -vi filesystem |sort -n -k4 |tail -n1 |awk '{print $NF}'`

if [ $f_size -lt $disk_size ]then read -p "Are U sure delete the file or directory: $1? y|n: " c case $c in y|Y) mkdir -p $big_filesystem/.$d && rsync -aR $1 $big_filesystem/.$d/$1 && /bin/rm -rf $1 ;; n|N) exit 0 ;; *) echo "Please input 'y' or 'n'." ;; esacelse echo "The disk size is not enough to backup the files $1." read -p "Do you want to delete $1? y|n: " c case $c in y|Y) echo "It will delete $1 after 5 seconds whitout backup." for i in `seq 1 5`; do echo -ne ". "; sleep 1;done echo /bin/rm -rf $1 ;; n|N) echo "It will not delete $1." exit 0 ;; *) echo "Please input 'y' or 'n'." ;; esacfi

相關文章
相關標籤/搜索