#!/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