当前位置: > shell编程 >

shell控制运行次数(根据日期判断)

时间:2014-11-05 12:08来源:linux.it.net.cn 作者:IT
分享一例shell脚本,学习下在shell中控制代码运行次数的方法,本例中以日期为判断基准。

在shell脚本中,控制运行次数的方法。

在shell中,控制具体的次数可加入次数字段。

例子:
 

代码示例:
#!/bin/bash
#

update()
{
date_d=`date  "+%Y-%m-%d"`
echo "$date_d"    >>run_file
echo "update 完成,将日期写入run_file文件中(标记单天已运行过)"
}
run_check()
{
       if [ -f run_file ];then
               run_date=`awk 'END {print$0}'  run_file`
               if  [ $run_date = $date_d ];then
                       echo "$date_d已运行过一次,退出"
                       exit 0
               else
                       echo "$date_d未有运行记录,调用update运行"
                       update
               fi
       else
               update
       fi
}
main()
{
run_check
}
main
 
(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容