bat实现每天定时执行命令[windows底下每天重启一下Nginx]
--试验通过
--Windows环境
脚本名称:restart.bat
脚本内容:
@echo off
taskkill /f /fi "IMAGENAME eq nginx.exe"
cd /d D:\nginx\nginx-1.11.10\
nginx.exe
#pause
at命令:
at 9:47 /every:M,T,W,Th,F,S,Su D:\nginx\restart.bat
restart.bat
cd D:\YFZ\nginx-1.20.1
nginx -s reload
nginx -s quit
taskkill /f /t img nginx.exe
start nginx
nginx -V
cmd
at 12:28 /every:M,T,W,Th,F,S,Su D:\YFZ\restart.bat
restart_tomcat.bat
@echo off
taskkill /f /fi "IMAGENAME eq Tomcat.exe"
cd /d E:\apache-tomcat-8.0.36-windows-x64\apache-tomcat-8.0.36\bin\
startup.bat
#pause
比如希望电脑在每天03:00自动关机:
at 03:00 /every:M,T,W,Th,F,S,Su "shutdown -s"
M就是Monday,T就是Tuesday,后面类推,意思就是每周的每一天都运行。
Linux版本:
nginx:
chrontab -e
*/5 * * * * ./usr/local/nginx/sbin/nginx
tomcat:
restart_tomcat.sh