Scheduled Activity: cron and at
Use at when you want to execute a command or multiple commands once at some future time.
In Linux, the at command requires that the atrun command be started in root's crontab file. Many Linux distributions ship with at enabled, but some do not. To enable the at utility on your system, become superuser and edit root's crontab file:
$ su root Password: # crontab -e
and add the following line:
* * * * * directory/atrun
where directory is the location where the atrun executable is stored. On my system that's /usr/lib, so the entry is:
* * * * * /usr/lib/atrun
This causes atrun to be executed every minute. After a minute or so of adding the atrun line and saving the crontab file, any existing at commands are evaluated and executed if the time is right. (Before this, you may have been able to enter at commands, but they were never executed.)
To demonstrate the at command, let's have it print “hello” on your current terminal window after a few minutes. First, get the time and your current terminal device:
$ date Tue Oct 3 15:33:37 PDT 1995 $ tty /dev/ttyp2
Now run the at command. Specify a time in the command line, press Return, and then enter the command, followed by another Return and a Ctrl-D:
$ at 15:35 echo "hello" > /dev/ttyp2 ^D Job c00ceb20b.00 will be executed using /bin/sh
The at command takes input up to the end-of-file character (generated by pressing ctrl-D while at the beginning of a line.) It reports the job number and informs you that it will use /bin/sh to execute the command. In two minutes, hello should appear on the display of /dev/ttyp2. Note that you can enter a series of commands, one per line—at will read each line up to the end-of-file and execute the file as a /bin/sh shell script at the specified time.
Suppose you want to set an alarm. One way to tell at to do something is to use the relative form of timing, specifying a time relative to now. If you want your computer to beep at you in 25 minutes, enter:
$ at now + 25 minutes echo ^G > /dev/ttyp4 ^D Job c00ceb7fb.00 will be executed using /bin/sh
and you are beeped in 25 minutes. There is a great deal of flexibility allowed in entering time specifications. For example, at recognizes military time, “am” and “pm”, month abbreviations, time notation that includes the year, and so on. My at man page even claims at accepts teatime, noon, and other constructs. Refer to the at man page for more examples of valid time specifications.
You must tell at your tty location, or it won't send output to your terminal window. If you prefer, you can receive mail:
$ at 4:55pm Friday echo '5 p.m. meeting with Carol' | mail raithel ^D Job c00ceb7fb.01 will be executed using /bin/sh
To get a list of your pending at jobs, enter:
$ atq
If you are superuser, atq shows you the pending at jobs of all users. To delete a job, enter:
$ atrm job_number
where job_number is the job number returned by atq. The superuser can also remove other user's jobs.
The following is a simple script that makes it easier for me to use at to send myself reminders. The script sends mail to the user containing the message line(s) entered at the prompt at the time specified. It also displays some syntax examples of how to specify time, which I find a useful memory refresher.
Notice the script, as written, requires you to have a Msgs directory in your home directory. I created $HOME/Msgs, rather than using something like /usr/tmp, so the messages are more private until they are deleted by the script.
#!/bin/sh
echo "Enter your reminder message.
When finished, enter a period (.) at
the beginning of a line and press Enter.
(Or press Ctrl-C or DEL to exit.)"
while :
do
read MESSAGE
if [ "$MESSAGE" = "." ]
then
break
else
echo $MESSAGE > $HOME/Msgs/message.$$
fi
done
cat << !!
Enter time and day you want to receive
the message, for example:
0815am Jan 24
8:15am Jan 24
now + 1 day
5 pm Friday
Then press Enter.
!!
read TIME
echo \
"at $TIME mail $LOGNAME $HOME/Msgs/message.$$"
at $TIME << !!
mail $LOGNAME < $HOME/Msgs/message.$$
rm -f $HOME/Msgs/message.$$
!!
exit 0
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- New Products
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- Designing Electronics with Linux
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




6 hours 2 min ago
16 hours 42 min ago
22 hours 28 min ago
22 hours 46 min ago
1 day 39 min ago
1 day 2 hours ago
1 day 9 hours ago
1 day 9 hours ago
1 day 11 hours ago
1 day 17 hours ago