Linux Classes
Share This With a Friend  

Can I Schedule a Task with Linux?

Linux provides a really handy way to schedule future events so they run automatically. You can use the at command to schedule reminders or administrative tasks or to run a command later when the computer won't be busy. After you specify the time (and optional date) for your event, at prompts you for the command to run. After entering your command, press ctrl-D to finish. Here are some examples:

at 8:15am Jul 14
echo "Remember to call Ruth about the Amalgamated Contract!"
at midnight Friday
cp project/source backup

To find out what events you have already scheduled with at, enter the following:

at -l
Date Owner Queue Job#
08:15:00 07/14/97 root c 1
00:00:00 01/10/97 root c 2

To cancel an event scheduled with at, use the -r switch and a job number (which you can find using the at -l command). For example, to cancel job 2, you would ent er

at -r 2

Previous Lesson: Comparing Files
Next Lesson: Linking Files



Comments - most recent first
(Please feel free to answer questions posted by others!)

venkat     (28 Dec 2015, 10:50)
How to check the cancelled Scheduled jobs in linux Server. Can u tell me the cmd pls.
Koong     (30 May 2013, 04:11)
Thank you.
Prescilla     (03 Feb 2013, 05:58)
I am a newbie and would like to know where is the mail sent when -m is used? Or how or where do I check that mail?
Raf     (23 Jan 2013, 17:44)
Good command but...
is there a way to know if a job is already scheduled? It is possible with at? or is it possible with another command? I need to run job only once (so i don't want to use cron). Thanks!
Harshit     (21 Dec 2012, 17:41)
Scheduling job by at , but job not getting execute.
if i run job manully it runs fine gives output.

but using at nothing is moving, job is also presented on atq.
Bob Rankin     (16 Mar 2012, 09:15)
@Sruthi - When cron executes a command, the output is mailed to the owner of the crontab. Just login as that user and run the mail command to see it.
Sruthi     (16 Mar 2012, 07:08)
Is there a way that crontab sends an email when the task is finished. I am using crontab to schedule my task. Once the job is completely done, I like to get the response as a mail. I am using something like below.
* * * * * >> /test.out 2>&1
Please guide how to send the mail and where to check the mail in case I send the mail to local user.

Igor     (09 Dec 2011, 13:28)
@Rick (9 Sept. 2010)

Obviously it's been a while since your comment. I think your woes might have something do to with this (copy/paste from at's manpage):

-q queue
uses the specified queue. A queue designation consists of a
single letter; valid queue designations range from a to z. and
A to Z. The a queue is the default for at and the b queue for
batch. Queues with higher letters run with increased niceness.
The special queue "=" is reserved for jobs which are currently
Kuldeep Thakur     (06 Dec 2011, 02:55)
I am using the same command at 8:15am Dec 16
echo "Remember to call Ruth about the Amalgamated Contract!"
but instead of giving me the result it's shows me you have a mail in /var/spool/mail/kthakur
then i tried to go to that path i haven't permission for that.
please suggest!
Diandra     (24 Oct 2011, 08:49)
Whoa, thgnis just got a whole lot easier.
JUICE     (21 Jul 2011, 21:11)
How would the at command find me in a specific point in time if it doesnt know my current terminal? what can be the command to use that "at" would determine my location and run a specific txt file.?
scottathena     (06 Jun 2011, 07:15)

I don't know if this has been solved, but I believe there is a space between the 'r' and 'job number', so I would try something like "at -r 1"
Brad     (21 Feb 2011, 20:53)
Great material -- a brilliant self-study course. One question about this page: I tried to cancel a task using at -r1 but I keep getting an error: 'at invalid option -- r'. I know the task is scheduled because it appears in at -l. Any suggestions? I'm using Linux Mint 9. Thanks.
dheeraj     (02 Dec 2010, 13:03)
this is really very cool command . i will definately try it
and keep uploading more commands !
rick     (09 Sep 2010, 17:35)
Ok, thanks Bob.
Bob Rankin     (09 Sep 2010, 15:48)
@Rick - I can't explain the behavior, but maybe you could use the renice command to change the nice value of the process.
Rick     (09 Sep 2010, 14:53)
I used "at" to schedule some (single threaded) timing runs (using /usr/bin/time) of a computationally intensive, I/O unintensive (as in just 2-3 pages of text output) program I'm working on last night. (OS is Ubuntu 7.10) The output this morning showed that each run of the program had taken ~2-3x as long to run as normal, i.e., the reported user time is 2-3x as large. I just looked at a small subset of the test, and, yep, the program does run more slowly under at. Just checked using "crontab" to do the same thing and did not see any slowdown from running interactively. The only hint I saw is that with "at" the program is niced to 2 while with crontab the program runs at a nice of 0. Sure enough, when I run interactively with a nice value of 2 I see the same slow down -- which puzzles me because while running with a nice of 2, top reports that I am getting 100% of a CPU. BTW, the runs are long enough to be significant -- ~105 seconds of CPU time, ~300 sec under "at". So my 2 questions are: 1) how can I tell "at" not to nice my job? 2) why would running with a nice of 2 when there's no load on the machine slow my job down so? Any thoughts would be appreciated.
Bob Rankin     (18 Jun 2010, 05:47)
@Felipe - the at command has a -m flag to send mail when done.
Felipe     (15 Jun 2010, 08:11)
Is there a way that the "at" sends me an email when the task has finished?
JensCarsten     (31 May 2010, 16:40)
What linux distro are you using?
In Debian, it's 'at -d' to delete a job from the queue.
eddiehaskell     (30 Apr 2010, 21:36)
You may wish to explain that 'at' is for one time, 'cron' is for recurring events.

I welcome your comments. However... I am puzzled by many people who say "Please send me the Linux tutorial." This website *is* your Linux Tutorial! Read everything here, learn all you can, ask questions if you like. But don't ask me to send what you already have. :-)

NO SPAM! If you post garbage, it will be deleted, and you will be banned.
Notify me about new comments on this page
Hide my email

Ask Bob Rankin - Free Tech Support

Copyright © by - Privacy Policy
All rights reserved - Redistribution is allowed only with permission.