如何取消 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 -cjobid 來查看將為此作業 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.

進一步閱讀

相關內容