1

I have been doing some research on scheduling tasks and what not. I came across the crontab command function.

Is crontab a file that is created or is it a command?

If it is a file, then how many can one user have? Are they user-specific or system-specific (for instance, if I create a task using crontab, will the task execute if another user logs in to the system?)

If it is a command, where does it store the info for executing tasks?

3
  • 1
    You should wait with accepting an answer for a day or so. Maybe others come by that have an even better answer than mine. Yes, accepting an answer is important for this website to work optimally, but most important is that you get the best answer possible. Many people won't look at a question that is marked as answered and therefore won't leave their insight.
    – jippie
    Nov 5, 2012 at 21:11
  • ah i see what you're saying, i just thought i'd mark your answer for the purpose of others but you raise an important point. NOTED! Nov 6, 2012 at 0:07
  • I think cron, crontab, at, and anacron are all a bit too broad to be Ubuntu-specific. Go to the Unity Dash (or similar) and look for "Scheduled Tasks"
    – user29020
    Jul 16, 2014 at 19:07

2 Answers 2

1

The command crontab -e will create a file, but you don't need to know about that and should never edit it by hand.

man crontab shows you the various options, most important ones being:

  • crontab -e edit
  • crontab -l list

Notice that your environment as a cron job is quite different from the one you are used to in an interactive shell. Easiest to inspect this is to set a cron job as follows:

* * * * * set > /tmp/environment.log

# | | |  \day of week    0-7 (0 or 7 is Sun, or use names)
# | |  \--month          1-12 (or names, see below)
# |  \----day of month   1-31
#  \------hour           0-23
#\--------minute         0-59

For the syntax of the crontab itself check man 5 crontab.

Then wait for a minute and remove the cronjob again, because otherwise this nonsense job will run every minute.

Then check the difference between the interactive shell (just type set) and the cronjob (just type cat /tmp/environment). Especially PATH and SHELL may surprise you.

3
  • thanks @jippie! Are they system tasks that run regardless of what user is logged in or user specific? Nov 5, 2012 at 21:02
  • You don't need to be logged on, cronjobs will always run as configured (the * * * * * part). They will run however by default as the user who created the crontab.
    – jippie
    Nov 5, 2012 at 21:04
  • Answering my own Question: Extract from wikipedia: "...Users can have their own individual crontab files and often there is a system wide crontab file (usually in /etc or a subdirectory of /etc) which only system administrators can edit..." Nov 5, 2012 at 21:04
0

If you are interested in scheduling tasks as a normal user account in Ubuntu (i.e. you're not doing system-wide things as root), then you should skip all the specifics of cron, crontab, at, and anacron.

Instead, look at the Scheduled Tasks application available in Ubuntu via the Unity Dash or similar applications menu. It vastly simplifiies the work of scheduling items. There are some "gotchas" related to its use, but this way you don't have to do anything in the command line.

For example, I have a little backup script that I run periodically using Scheduled Tasks. (The program basically inserts items into your crontab, etc.)

Scheduled Tasks provides two different views. One view is simplified, like this:

enter image description here

The other view shows what the crontab would show:

enter image description here

One of the "gotchas" is that your normal "PATH" is not available for a specific scheduled item, so you need to be explicit about what command is to be run.

Anyway, the details of cron, crontab, at, and anacron are all a bit too broad to be Ubuntu-specific.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .