循环脚本

声明:允许转载,转载请注明链接,谢谢合作!
很多时候我们在执行sh命令需要执行一个时间段的脚本任务,循环调用是很常见的,以下的脚本用于递归执行一个时间段的脚本。
代码如下:
#!/bin/sh
#circle_operate.sh     脚本名称
#run shell script between two date
#程序递归脚本
#OPERATE_DATE         操作数据日期
#author:wangxin     version:1.0 
#create_date:20160202 
##################################################################
#check the input param num is correct
#判断入参个数是否正确
#check the first param is not empty
if [ -z "$1" ]; then
echo "param1 error "
echo "you need to input a pre_commond"
echo "the correct formate is :   ./circle_operate.sh   commond1 start_date end_date commond2"
exit 
fi
#check the second param is not empty
if [ -z "$2" ]; then
echo "param2 error "
echo "you need to input a start date"
echo "the correct formate is :   ./circle_operate.sh   commond1 start_date end_date commond2"
exit 
fi
#check the third param is not empty
if [ -z "$3" ];then
echo "param3 error "
echo "you need to input a end date"
echo "the correct formate is :   ./circle_operate.sh   commond1 start_date end_date commond2"
exit 
fi
#check the fourth param is not empty
if [ -z "$4" ];then
echo "param4 error "
echo "you need to input a end_commond"
echo "the correct formate is :   ./circle_operate.sh   commond1 start_date end_date commond2"
exit      
fi
#
#
echo "program start"
#Achieve first commond 
#获取前部分命令
begin_commond=$1
echo "begin_commond is $begin_commond"
#
#Achieve start_date
#获取开始日期
begin_date=$2
echo "begin_date is $begin_date"
#
#Achieve end_date
#获取结束日期
end_date=$3
echo "end_date is $end_date"
#
#Achieve start_date
#获取后部分命令
end_commond=$4
echo "end_commond is $end_commond"
#
#mark the last_date
#明确结束日期
last_date=`date -d $end_date' next-day' '+%Y%m%d' `
echo "the script will exit before $last_date"
#
#set operate_date
#给运行日期赋值
operate_date=$begin_date
#
while [ $operate_date -lt $last_date ]
do
echo "the current operate_date is $operate_date"
echo "$begin_commond $operate_date $end_commond"
operate_date=`date -d $operate_date' next-day' '+%Y%m%d' `
done
#
echo "program exit"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值