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