批处理脚本,把休眠状态,直到一定时间 [英] batch script, put to sleep until certain time
问题描述
我有我的计划发生每6小时一次或两次的问题。所以我想知道是否有什么办法可以让批处理脚本不断地在后台运行,并且只在下午和午夜执行它是在早上6点给出的命令,中午,晚上6。
I have an issue with my program that occurs once or twice every 6 hours. So I was wondering if there is any way I can get the batch script to constantly run in the background, and only execute the command it is given at 6 in the morning, at noon, at 6 in the afternoon and at midnight.
我的剧本只是一个命令,它是
my script is just one command which is
"C:\Program Files\WinSCP\WinSCP.com" /command "open %INPUT%" "get /etc/logs/*" "get /etc/network/interfaces" "bye"
我已经打破了我的脖子,似乎无法找出一个办法让节目入睡,未用完的CPU,直到一天中的某个时间。
I have been breaking my neck and can't seem to figure out a way to get the program to sleep and not use up cpu until a certain time of day.
推荐答案
该批处理文件低于6,12,18日和0小时执行命令:
The Batch file below execute the command at 6, 12, 18 and 0 hours:
@echo off
:waitNextRun
for /F "delims=:" %%h in ("%time%") do set hour=%%h
set /A mod6=hour %% 6
if not %mod6% == 0 goto waitNextRun
"C:\Program Files\WinSCP\WinSCP.com" /command "open %INPUT%" "get /etc/logs/*" "get /etc/network/interfaces" "bye"
:waitNextHour
for /F "delims=:" %%h in ("%time%") do if %hour% == %%h goto waitNextHour
goto waitNextRun
不过,此批处理文件并没有后台运行,但作为一个正常的批处理文件。您可以通过以下命令启动它减少它的CPU使用:
However, this Batch file does not run "in the background", but as a normal Batch file. You may minimize its CPU use by starting it via this command:
START "Run WinSCP every six hours" /MIN /LOW theBatchFile
这篇关于批处理脚本,把休眠状态,直到一定时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!