At Command - Schedule One-Time Tasks | Online Free DevTools by Hexmos

Schedule one-time tasks with the

At Command

Schedule One-Time Tasks with the 'at' Command

The at command is a powerful utility in Unix-like operating systems that allows you to schedule commands to be executed at a specific time in the future. Unlike cron, which is designed for recurring tasks, at is ideal for one-time jobs. This makes it perfect for tasks that need to run once, such as system maintenance, backups, or sending out notifications at a particular moment.

Understanding the 'at' Command Syntax

To schedule a one-time task using the at command, you specify the desired execution time followed by the commands you want to run. The commands are then entered one by one, and you signal the end of the input by pressing Ctrl-d.

# To schedule a one time task:
at <time>
<command 0>...
Ctrl-d

Specifying Execution Times

The <time> argument for the at command is quite flexible and can be specified in several formats:

  • now: Executes immediately.
  • midnight: Schedules for midnight (00:00) of the next day.
  • noon: Schedules for noon (12:00) of the next day.
  • teatime: Schedules for 4 PM (16:00) of the next day.
  • HH:MM: Specifies the exact hour and minute (e.g., 14:30 for 2:30 PM).
  • now + N <minutes | hours | days | weeks>: Schedules relative to the current time (e.g., now + 30 minutes or now + 2 days).
  • MM/DD/YY: Specifies the date in month/day/year format (e.g., 12/25/23 for December 25, 2023).

Managing Scheduled Jobs

The at command suite includes utilities to manage your scheduled tasks effectively.

Listing Pending Jobs

To view a list of all jobs that are currently scheduled to run but haven't executed yet, use the atq command:

# To list pending jobs:
atq

This command will output a list of job IDs, along with the date and time they are scheduled to run.

Removing Scheduled Jobs

If you need to cancel a scheduled job, you can use the atrm command followed by the job ID obtained from atq:

# To remove a job (use id from atq):
atrm <id>

For example, if atq shows job ID 5, you would run atrm 5 to remove it.

External Resources