Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

What's a simple way to run a command, say, 8 hours from now? I can think of this way:

nohup bash -c "sleep 28800 ; ./mycommand.sh" &

Is there a more "proper" way?

share|improve this question

3 Answers 3

up vote 47 down vote accepted

You can use the at command. The at execute commands at a later time. The at utility shall read commands from standard input and group them together as an at-job, to be executed at a later time.

at is not installed by default and can be installed via:

sudo apt-get install at

For more information, options, examples, and others see the Ubuntu Manpage Repository


at now +8 hours -f ~/myscript.sh

You can also use convenient shorthands, like tomorrow or noon, as in

echo "tweet fore" | at teatime 

The example also demonstrates how you can pipe actions into at. at -c is the way you can examine scheduled actions, which you can conveniently list with their number, as with:

at -c 3
share|improve this answer
It might be helpful to add a simple usage example that addresses the original poster's question more specifically e.g. at now +8 hours -f ~/myscript.sh –  steeldriver Aug 30 '13 at 12:12
In addition, there is at 8:00 to run the command at an absolute time, and batch for "when it looks like the computer is idle" –  Simon Richter Aug 30 '13 at 18:09
In case anyone was wondering, teamtime is at 4pm. For some reasons it's not mentioned in manpages.ubuntu.com/manpages/raring/man1/at.1posix.html but it is in man at and here manpages.ubuntu.com/manpages/raring/en/man1/at.1.html. –  Dan Sep 6 '13 at 7:53
Wow, batch looks like a really useful command (although its mode of operation is weird - no arguments.) –  Steve Bennett Sep 9 '13 at 12:34
Maybe we can mention that "at" utility is not installed by default and if anyone else want to get it simply install the "at" package? Edit: Anyway, i simply edited the answer (also fixed the manpage link). –  heartsmagic Feb 12 '14 at 10:11

Yes, you can set a cron job.

For example if now the time is 14:39:00 and today is friday, 30 august, you can add the following cron job (to be executed after 8 hours) in your crontab file using crontab -e command:

39 22 30 8 5  /path/to/mycommand.sh

More about:

share|improve this answer
Ok, yes, I should have mentioned I know about Cron jobs. This is even messier because then it sits around in the crontab indefinitely, right? –  Steve Bennett Aug 30 '13 at 12:55
@SteveBennett As in my example, no: 5 means friday, 8 means august, 30, means today. –  Radu Rădeanu Aug 30 '13 at 12:58
@RaduRădeanu: with cron, careful that it could fire again in a few years (when there is another 30th of August occuring on a friday) ... –  Olivier Dulac Aug 30 '13 at 13:12
@OlivierDulac The current version of Ubuntu will be probably EOF at that time (30 august 2019) :) –  Radu Rădeanu Aug 30 '13 at 13:13
This is a clever hack. However 'at' is a much better way. What would happen if the computer was turned off at 14:39? –  emory Aug 30 '13 at 14:47

Use the Gnome-based GUI for cron, at, and the like:

The introduction of the CronHowto suggests using the gnome-schedule gui, which is much nicer than typing all the garbage into the terminal (esp. for "average" Ubuntu users who are not "power" *nix/bsd users.)

Run it by using the Unity Dash (or other applications menu) to look for Scheduled Tasks or running gnome-schedule.

On Gnome-based Ubuntu systems Gnome Scheduled tasks tool (from the gnome-schedule package) in Applications --> System Tools provides a graphical interface with prompting for using Cron. The project website is at http://gnome-schedule.sourceforge.net/; the software is installable from the Software Center or by typing

sudo apt-get install gnome-schedule

in a terminal.

Using gnome-schedule, for a script in your home directory, a new "at" command would be set up using this type of window:

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.