如何取消 CMD 的预定命令

如何取消 CMD 的预定命令

我刚刚安排了一个休眠命令:

at 13:00 shutdown /h

是否有任何命令可以中止此计划的操作?

  1. shutdown /a没有用,它说没有计划关机。

  2. At 12:59 shutdown /a对于堕胎没有起到很好的作用At 13:00 shutdown /h

答案1

在我的例子中atq,列出所有等待安排的作业at。示例输出:

atq
2   Fri May  1 06:00:00 2020 a root
1   Fri May  1 05:00:00 2020 a root

如果您需要更多信息来了解哪个作业是哪个,您可以运行at -c后跟 jobid 来查看将针对此作业 ID 执行的命令。例如:

at -c 1
#!/bin/sh
umask 22
LANG=bg_BG.UTF-8; export LANG
SUDO_GID=1000; export SUDO_GID
...
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin; export PATH
...
ls

(省略部分输出,并替换为...

然后atrm后面跟上作业 ID 来删除某个计划作业。示例(成功时没有输出):

atrm 1

答案2

仅当使用命令安排关机后,Shutdown /a 才会起作用

因此等待关机事件触发,然后运行shutdown /a

所以如果你在 13.01 上运行它,它会起作用

答案3

是否有任何命令可以中止此计划的操作?

at 13:00 shutdown /h

您可以at单独运行以列出计划的作业。例如:

F:\test>at 13:00 echo "hello"
Added a new job with job ID = 1

F:\test>at
Status ID   Day                     Time          Command Line
---------------------------------------------------------------------
        1   Tomorrow                13:00         echo hello

这将返回已安排的作业列表以及ID每个作业的列表。

要删除计划作业:

at ID /delete

例子:

F:\test>at 13:00 echo "hello"
Added a new job with job ID = 1

F:\test>at
Status ID   Day                     Time          Command Line
-------------------------------------------------------------------------------
        1   Tomorrow                13:00         echo hello

F:\test>at 1 /delete

F:\test>at
There are no entries in the list.

要删除计划作业,请使用schtasks

schtasks /delete /tn At{ID}

{ID}任务的 ID 在哪里at

例子:

F:\test>schtasks /delete /tn At1
WARNING: Are you sure you want to remove the task "At1" (Y/N)? y
SUCCESS: The scheduled task "At1" was successfully deleted. 

删除全部预定作业:

at /delete /yes

使用时

F:\test>at /?
The AT command schedules commands and programs to run on a computer at
a specified time and date. The Schedule service must be running to use
the AT command.

AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
    [ /EVERY:date[,...] | /NEXT:date[,...]] "command"

\\computername     Specifies a remote computer. Commands are scheduled on the
                   local computer if this parameter is omitted.
id                 Is an identification number assigned to a scheduled
                   command.
/delete            Cancels a scheduled command. If id is omitted, all the
                   scheduled commands on the computer are canceled.
/yes               Used with cancel all jobs command when no further
                   confirmation is desired.
time               Specifies the time when command is to run.
/interactive       Allows the job to interact with the desktop of the user
                   who is logged on at the time the job runs.
/every:date[,...]  Runs the command on each specified day(s) of the week or
                   month. If date is omitted, the current day of the month
                   is assumed.
/next:date[,...]   Runs the specified command on the next occurrence of the
                   day (for example, next Thursday).  If date is omitted, the
                   current day of the month is assumed.
"command"          Is the Windows NT command, or batch program to be run.

进一步阅读

相关内容