定时调度shell

 

scheduler.sh

#!/bin/bash

./timing.sh 201401271339

if [ "$?" -eq 0 ]; then

    echo "调度命令写在这里"

    echo `date +"%Y-%m-%d %X"`"程序已调起"

else

    echo "调度失败"

fi

 

timing.sh

#! /bin/bash

#shellname=$1

runtime=$1

currenttime=`date +%Y%m%d%H%M`

 

if [ $# != 1 ] || [ `expr length $runtime` != 12 ]; then

    echo "参数数目不对或日期参数格式不正确"

    exit 1

else

    #let timediff=runtime-currenttime

    #timediff=`expr ${runtime} - ${currenttime}`

    #start=`date +%s -d "2011-11-28 15:55:37"`

    #end=`date +%s -d "2011-11-28 15:56:52"`

    #echo $(($end-$start))

    runtime_a=`echo $runtime|cut -b 1-4`"-"`echo $runtime|cut -b 5-6`"-"`echo $runtime|cut -b 7-8`" "`echo $runtime|cut -b 9-10`":"`echo $runtime|cut -b 11-12`":00"

    runtime_b=`date +%s -d "$runtime_a"`

    currenttime_b=`date +%s`

    let timediff_h=($runtime_b-$currenttime_b)/3600   

    let timediff_m=($runtime_b-$currenttime_b)%3600/60

    echo "距离您设置的调度时间还有:${timediff_h}小时${timediff_m}分钟,如果时间设置有误,请杀掉该进程,重新定时"

fi

 

 

#定时调度

for ((i=1;i<3600;i++))

do

    currenttime=`date +%Y%m%d%H%M`

    if [ "$runtime" -le "$currenttime" ]; then

        echo "时间已到"

        break

    else

        sleep 5m

    fi

done

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值