使用shell/ target=_blank class=infotextkey>shell脚本创建日期目录,步骤如下:
步骤1,vi create_dir.sh
#!/bin/sh
create_dir()
{
if test -z "$2"
then
next_month=`date -d next-month +%Y%m` #get next month 参数2为空则创建下个月
else
next_month=$2 #根据输入参数2 创建
fi
year=`echo ${next_month}|cut -c1-4`
month=`echo ${next_month}|cut -c5-6`
rman_path_root=$1 #/u01/rman_backup
l_cal=`cal $month $year`
l_days=`echo $l_cal|linuxjishu/13830.html target=_blank class=infotextkey>awk '{print $NF}'`
l_zero=0
leng=`expr length $month`
if [ $leng -lt 2 ]
then
month=${l_zero}${month}
else
month=${month}
fi
year_path=${rman_path_root}/${year}
month_path=${year_path}/${year}${month}
if ! [ -d ${year_path} ]
then
mkdir -p ${year_path}
fi
if ! [ -d ${month_path} ]
then
mkdir -p ${month_path}
fi
for((i=1;i<=$l_days;i++));
do
leng=`expr length $i`
if [ $leng -lt 2 ]
then
l_run_day_path=${month_path}/${year}${month}${l_zero}${i}
else
l_run_day_path=${month_path}/${year}${month}${i}
fi
##create dir
if ! [ -d ${l_run_day_path} ]
then
mkdir -p ${l_run_day_path}
fi
echo $l_run_day_path
done
}
create_dir /u01/rman_backup
create_dir /u01/rman_backup/level_0_bak
create_dir /u01/rman_backup/level_1_bak
create_dir /u01/rman_backup/level_2_bak
步骤2,加上执行权限
步骤3,使用linux的crontab调度该脚本自动创建日期目录
有关crontab的用法,请参考文章: