加入收藏 | 设为首页 | 会员中心 | 我要投稿 济南站长网 (https://www.0531zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

程序时间控制的脚本

发布时间:2016-10-03 06:08:11 所属栏目:Linux 来源:站长网
导读:#!/bin/bash #自动下载自动开启关闭脚本 #定义开始时间,000101表示00:01:01 datestart=000101 #定义结束时间,180101表示18:01:01 dateend=180101 #自动和网络时间同步,避免时间故障 sntp -P no -r pool.ntp.org #获取当前系统的时区 zone=`awk /TZif2/ /e
#!/bin/bash     


#自动下载自动开启关闭脚本     
#定义开始时间,000101表示00:01:01     
datestart=000101    
#定义结束时间,180101表示18:01:01     
dateend=180101    
#自动和网络时间同步,避免时间故障     
sntp -P no -r pool.ntp.org     
#获取当前系统的时区     
zone=`awk /TZif2/ /etc/localtime |cut -c1-5`     
zone="TZif2"
[ $zone != 0 ];rm /etc/localtime;     
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime     
#获取当前系统时间     
date=`date --date=-24hour +%H%M%S`     
#查看当前进程是否运行     
downloader=`ps -ef |grep "/home/downloader/downloader" |grep -v grep|awk '{print $8}'|cut -c22-31|uniq`     
#判断时间是否为下载时间,是,则进行下载     
if [ $downloader = "downloader" ]     
then exit 1     
  elif  [  $date -ge $datestart -a $date -lt $dateend  ]     
then `nohup /home/downloader/downloader > /dev/null &`;status=$?     
   [ $status = 0  ] && echo "***********Now is $date,start downloader***********************" >>/var/log/start_downloader.log     
   [ $status != 0  ] && echo "**********Now is $date,start downloader,but can't find the program" >>/var/log/start_downloader     
.log     
        
elif [ $date -gt $dateend ]     
then `ps -ef |grep down|grep -v grep|awk '{print $2}'|xargs kill -9`;status=$?     
   [ $status != 0  ] && echo "***********Now is $date,the program is not running,stop error**************"  >>/var/log/stop_d     
ownloader.log     
   [ $status = 0  ] && echo "***********Now is $date,killed downloader*****************" >>/var/log/stop_downloader.log     
        
        
#elif [ $down != 0 ] && [ $date -le $dateend ]     
#then `nohup /home/downloader/downloader > /dev/null &`     
#echo "*********Now is $date,the process is not running,started it" >>/var/log/start_downloader.log     
else 
echo "*********no such a file,please check the process url">>/var/log/start_downloader.log     
fi     
exit 1     
0

本文出自 “itnihao的运维技术博客” 博客,请务必保留此出处http://itnihao.blog.51cto.com/1741976/681574

(编辑:济南站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读