0
0
Linux CLIscripting~10 mins

at command for one-time jobs in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - at command for one-time jobs
User types 'at' with time
System waits for commands
User enters commands
User signals end (Ctrl+D)
System schedules job
Job runs at scheduled time
Job output sent to user (optional)
The 'at' command schedules commands to run once at a specified future time. User inputs commands, ends input, then system runs them later.
Execution Sample
Linux CLI
echo "echo Hello at 5 seconds" | at now + 5 seconds
Schedules a one-time job to print 'Hello at 5 seconds' after 5 seconds.
Execution Table
StepActionInput/CommandSystem ResponseOutput
1User runs at commandat now + 5 secondsat waits for commands
2User enters commandecho Hello at 5 secondsCommand accepted
3User signals endCtrl+DJob scheduledjob 1 at Thu Apr 27 12:00:05 2024
4Time passes 5 secondsJob runsHello at 5 seconds
5Job completesJob removed from queue
💡 Job runs once at scheduled time and then is removed from queue
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
Job Queueemptyjob 1 addedjob 1 scheduledjob 1 runningempty
Outputnonenonenone"Hello at 5 seconds"none
Key Moments - 3 Insights
Why does the 'at' command wait for input after I run it?
Because 'at' expects you to type the commands to run later. See execution_table step 1 and 2 where system waits and accepts commands.
How do I tell 'at' I finished entering commands?
You press Ctrl+D to signal end of input. This is shown in execution_table step 3.
What happens if I schedule a job but the time never comes?
The job stays in the queue until the scheduled time. It runs once then is removed, as shown in variable_tracker for Job Queue.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what command does the user schedule at step 2?
Aecho Hello at 5 seconds
Bat now + 5 seconds
CCtrl+D
Djob 1 at Thu Apr 27 12:00:05 2024
💡 Hint
Check the 'Input/Command' column at step 2 in the execution_table.
At which step does the job actually run and produce output?
AStep 3
BStep 2
CStep 4
DStep 5
💡 Hint
Look at the 'System Response' and 'Output' columns in execution_table step 4.
If the user forgets to press Ctrl+D, what happens?
AJob is scheduled immediately
Bat command keeps waiting for input
CJob runs twice
DJob is canceled automatically
💡 Hint
See key_moments about how 'at' waits for input until Ctrl+D is pressed.
Concept Snapshot
at command schedules one-time jobs
Syntax: at [time]
Type commands, end with Ctrl+D
Job runs once at scheduled time
Output sent by email or terminal
Use 'atq' to list jobs
Full Transcript
The 'at' command lets you schedule commands to run once at a future time. You run 'at' with a time, then type the commands you want to run later. When done, press Ctrl+D to finish input. The system schedules the job and runs it at the specified time. After running, the job is removed from the queue. For example, 'echo "echo Hello at 5 seconds" | at now + 5 seconds' schedules a job to print a message after 5 seconds. The job queue holds scheduled jobs until they run. If you forget to press Ctrl+D, 'at' keeps waiting for your commands. You can check scheduled jobs with 'atq'.