at batch atq atrm

安装 at

sudo apt install at

at 用法

  1. at [-q queue] [-f file] [-mMlv] timespec...
  2. # -q 默认为 a
  3. # -f 执行 file 里的指令

at 日期格式

  1. now: at now + n UNIT
    • n: 整数
    • UNIT: minutes/hours/days/weeks
  2. at TIME
    • TIME: HH:MM[am|pm] [MMDD[CC]YY | DD.MM.[CC]YY | [CC]YY-MM-DD]
    • SPECIAL TIME: TIME tomorrow/midnight/noon/teatime(4:00 p.m.)
  3. at TIME + n UNIT
    • TIME: HH:MM[am|pm]
    • UNIT: days/weeks

      at 示例

      ```bash $ at now + 10 minutes at> echo ‘I am a task’ > file1.txt at> #(CTRL + D)
  1. <a name="g0ozO"></a>
  2. ### `batch`
  3. ```bash
  4. # 当系统负荷小于某值时执行任务
  5. batch # -q 默认为 b
  6. at -b # 等价于 batch

atq

  1. # 查看任务队列中的任务
  2. atq

atrm

  1. # 移除任务
  2. atrm TASK_NUMBER...

/etc/at.allow /etc/at.deny

one username per line

cron

System Jobs

  • /etc/cron.allow
  • /etc/cron.deny
  • /etc/cron.hourly/
  • /etc/cron.daily/
  • /etc/cron.weekly/
  • /etc/cron.monthly/
  • /etc/crontab
    ```bash

    /etc/crontab

SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

Example of job definition:

.———————— minute (0 - 59)

| .——————- hour (0 - 23)

| | .————— day of month (1 - 31)

| | | .———- month (1 - 12) OR jan,feb,mar,apr …

| | | | .—— day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat

| | | | |

* user-name command to be executed

17 root cd / && run-parts —report /etc/cron.hourly 25 6 root test -x /usr/sbin/anacron || ( cd / && run-parts —report /etc/cron.daily ) 47 6 7 root test -x /usr/sbin/anacron || ( cd / && run-parts —report /etc/cron.weekly ) 52 6 1 * root test -x /usr/sbin/anacron || ( cd / && run-parts —report /etc/cron.monthly )

  1. `run-parts` : run scripts or programs in a **directory**.
  2. <a name="Eraul"></a>
  3. ### User Jobs
  4. `crontab -e` 编辑用户的 crontab,即 /var/spool/con/crontabs/USERNAME<br />`crontab -l` 列出用户的 crontab 里的内容<br />`crontab -r` 删除用户的 crontab 里的内容
  5. <a name="dj2tV"></a>
  6. ## rtcwake
  7. ```bash
  8. # rtcwake -m [type of suspend] [-s NUM_OF_SECONDS | -t time_t | --date timestamp]
  9. # -m
  10. # standby —The computer is put into standby mode, which saves some power over running normally but not nearly as much as the other options. This is the default setting and will be used if you omit -m .
  11. # disk —(hibernate) The current state of the computer is written to disk, and the computer is powered off.
  12. # mem —(sleep) The current state of the computer is written to RAM, and the computer is put into a low-power state, using just enough power to keep the memory preserved.
  13. # no —The computer is not suspended immediately. Only the wakeup time is set. This allows you to continue working; you have to remember to put the computer to sleep manually.
  14. # off —The computer is turned off completely. Wake will not work with this setting for everyone and is not officially supported, but it does work with some computers. It is included here for those who like to live dangerously.
  • rtc: real time clock
  • rtcwake ... && cmd1 在系统被唤醒后执行 cmd1