1.创建命令脚本compact.sh

写入内容:

#!/bin/bash
time_start=`date \"+%Y-%m-%d %H:%M:%S\"`
echo \"开始进行H 的大合并.时间:${time_start}\"
 
str=`echo list | h shell | sed -n \'$p\'`
#str=\"a,b,c\"
str=${str//,/ }
arr=($str)
length=${#arr[@]}
current=1
echo \"H 中总共有${length}张表需要合并.\"
echo \"balance_switch false\" | h shell | > /dev/null
echo \"H 的负载均衡已经关闭\"
 
for each in ${arr[*]}
do
        table=`echo $each | sed \'s/]//g\' | sed \'s/\\[//g\'`
        echo \"开始合并第${current}/${length}张表,表的名称为:${table}\"
        echo \"major_compact ${table}\" | h shell | > /dev/null
        let current=current+1 
done
 
echo \"balance_switch true\" | h shell | > /dev/null
echo \"H 的负载均衡已经打开.\"
 
time_end=`date \"+%Y-%m-%d %H:%M:%S\"`
echo \"H 的大合并完成.时间:${time_end}\"
((duration=$(date +%s -d \"$time_end\")-$(date +%s -d \"$time_start\")))
echo \"耗时:${duration}s\"

 

2.创建后台调用脚本start.sh

 

写入内容:

nohup ./compact.sh > log 2>&1 &
 

收藏 打印