首页 > 代码库 > Linux Windows 定时修改系统时间
Linux Windows 定时修改系统时间
#/bin/bash # beforTime=02:00 afterTime=08:00 beforTime=$(echo $beforTime | awk -F : {‘print $1‘}) afterTime=$(echo $afterTime | awk -F : {‘print $1‘}) Flag=0 while true do sleep 2s echo "date: $(date +"%Y-%m-%d %H:%M:%S")" if [ $(date +%H) -eq $beforTime ]; then CurDate=$(date +%d) ChangeDate=$(expr $CurDate - 1) date -s ‘$(date +"%Y-%m-$ChangeDate %H:%M:%S")‘ if [ $? -eq 0 ]; then echo "Changed date: $(date +"%Y-%m-$ChangeDate %H:%M:%S")" Flag=1 break fi fi done if [ $Flag -eq 1 ];then while true do sleep 2s echo "date: $(date +"%Y-%m-%d %H:%M:%S")" if [ $(date +%H) -eq $afterTime ]; then CurDate=$(date +%d) ChangeDate=$(expr $CurDate + 1) date -s ‘$(date +"%Y-%m-$ChangeDate %H:%M:%S")‘ if [ $? -eq 0 ]; then echo "Changed date: $(date +"%Y-%m-$ChangeDate %H:%M:%S")" Flag=0 break fi fi done fi
@echo off @set StartDate=05 @set ChangeDate=04 @set ChangeTime=18:59 @set endTime=19:00 @echo 开始任务:05号1点更改时间 @set ErrNum=0 :ProcessDate @if %ErrNum% EQU 1 (ping /n 5 127.0.0.1 > nul) @for /f "usebackq tokens=1,2,3 delims=-/ " %%i in (`date /t`) do ( set Year=%%i set Mon=%%j set TodayDate=%%k echo Real_Date: %%i-%%j-%%k %TodayDate% ) @if %TodayDate% NEQ %StartDate% ( set ErrNum=1 goto :ProcessDate ) :ProcessTime @if %TodayDate% EQU %StartDate% ( for /f "usebackq tokens=1,2 delims=-/ " %%a in (`time /t`) do ( if "%%a" NEQ "%ChangeTime%" goto :ProcessTime if "%%a" == "%ChangeTime%" call :ChangeCurDate :ProcessTime_2 for /f "usebackq tokens=1,2 delims=-/ " %%a in (`time /t`) do ( if "%%a" == "%endTime%" ( echo %Year%-%Mon%-%TodayDate% date %Year%-%Mon%-%TodayDate% goto :eof ) else ( goto :ProcessTime_2 ) ) ) ) :ChangeCurDate echo Change_Date: %Year%-%Mon%-%ChangeDate% @date %Year%-%Mon%-%ChangeDate% @goto :eof
本文出自 “专注于Oracle性能调优” 博客,谢绝转载!
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。