tar按时间打包的一个脚本
今天一个同事让我帮他写一个shell脚本,需求是这样的:调用他的程序,并给该程序传递两个数字参数,他的程序按参数生成文件,并对刚生成的文件打包。代码如下:
#!/bin/bash
#filename:getar
#desp:get a tar file from a dir!
out=`pwd`/admin_output
pike=/usr/bin/pike
if [ -n "$1" -a "$1" != "${1//[^0-9]/}” ];then
echo “The first parameter is not a number!”
exit
elif [[ $1 == "" ]];then
echo “The first parameter is null!”
exit
fiif [ -n "$2" -a "$2" != "${2//[^0-9]/}” ];then
echo “The second parameter is not a number!”
exit
elif [[ $2 == "" ]];then
echo “The second parameter is null!”
exit
else
#filename:getar
#desp:get a tar file from a dir!
out=`pwd`/admin_output
pike=/usr/bin/pike
if [ -n "$1" -a "$1" != "${1//[^0-9]/}” ];then
echo “The first parameter is not a number!”
exit
elif [[ $1 == "" ]];then
echo “The first parameter is null!”
exit
fiif [ -n "$2" -a "$2" != "${2//[^0-9]/}” ];then
echo “The second parameter is not a number!”
exit
elif [[ $2 == "" ]];then
echo “The second parameter is null!”
exit
else
touch /tmp/pike.tmp
sleep 10
$pike process_kaiqi_cid.pike $1 $2
while true;do
if [[ -e output/cid$2/standard/operamini-hifi_kaiqi-zh.jad && -e output/cid$2/standard/operamini-hifi_kaiqi-zh.jar ]];then
find `pwd`/output -type f -newer /tmp/pike.tmp | xargs tar czf $out/$1-$2.tgz >/dev/null 2>&1
rm -rf /tmp/pike.tmp
echo -e “\033[0;32;1mit’s ok\033[0m”
break
fi
done
fi
这篇文章目前没有评论