Где хранятся задания cron?

У тебя вопрос по панели управления для клиентов системы «Йа с понтом хостер-криворучко». Cpanel и вот это вот всё.
К тегу unix оно не имеет ни малейшего отношения.
потому что в юникс можно написать
crontab список_заданий.txt
и все загрузить.
А куда грузить в твоей панели — надо спрашивать пользователей панели, а не юникса.
Впрочем, в любом случае если у тебя там » много однотипных cron-задач», то ты все делаешь неправильно.
Get Started with Cron Jobs: Linux
![]()
How do I add cron job under Linux or UNIX like operating system?
Cron allows Linux and Unix users to run commands or scripts at a given date and time. You can schedule scripts to be executed periodically. Cron is one of the most useful tools in a Linux or UNIX like operating systems. It is usually used for sysadmin jobs such as backups or cleaning /tmp/ directories and more. The cron service (daemon) runs in the background and constantly checks the /etc/crontab file, and /etc/cron.*/ directories. It also checks the /var/spool/cron/ directory.
crontab command for cron jobs
You need to use the crontab command to edit/create, install, deinstall or list the cron jobs in Vixie Cron. Each user can have their own crontab file, and though these are files in /var/spool/cron/crontabs, they are not intended to be edited directly. You need to use crontab command for editing or setting up your own cron jobs.
Types of cron configuration files
There are different types of configuration files:
- The UNIX / Linux system crontab : Usually, used by system services and critical jobs that requires root like privileges. The sixth field (see below for field description) is the name of a user for the command to run as. This gives the system crontab the ability to run commands as any user.
- The user crontabs: User can install their own cron jobs using the crontab command. The sixth field is the command to run, and all commands run as the user who created the crontab
Note: This faq features cron implementations written by Paul Vixie and included in many Linux distributions and Unix like systems such as in the popular 4th BSD edition. The syntax is compatible with various implementations of crond.
How Do I install or create or edit my own cron jobs?
To edit or create your own crontab file, type the following command at the UNIX / Linux shell prompt:
$ crontab -e
Do I have to restart cron after changing the crontable file?
No. Cron will examine the modification time on all crontabs and reload those which have changed. Thus cron need not be restarted whenever a crontab file is modified.
Syntax of crontab (field description)
- 1: Minute (0–59)
- 2: Hours (0–23)
- 3: Day (0–31)
- 4: Month (0–12 [12 == December])
- 5: Day of the week(0–7 [7 or 0 == sunday])
- /path/to/command — Script or command name to schedule
Easy to remember format:
Your cron job looks as follows for system jobs:
Example: Run backup cron job script
If you wished to have a script named /root/backup.sh run every day at 3am, your crontab entry would look like as follows. First, install your cronjob by running the following command:
# crontab -e
Append the following entry:
0 3 * * * /root/backup.sh
Save and close the file.
MORE EXAMPLES
To run /path/to/command five minutes after midnight, every day, enter:
5 0 * * * /path/to/command
Run /path/to/script.sh at 2:15pm on the first of every month, enter:
15 14 1 * * /path/to/script.sh
Run /scripts/phpscript.php at 10 pm on weekdays, enter:
0 22 * * 1-5 /scripts/phpscript.php
Run /root/scripts/perl/perlscript.pl at 23 minutes after midnight, 2am, 4am …, everyday, enter:
23 0-23/2 * * * /root/scripts/perl/perlscript.pl
Run /path/to/unixcommand at 5 after 4 every Sunday, enter:
5 4 * * sun /path/to/unixcommand
How do I use operators?
An operator allows you to specify multiple values in a field. There are three operators:
- The asterisk (*) : This operator specifies all possible values for a field. For example, an asterisk in the hour time field would be equivalent to every hour or an asterisk in the month field would be equivalent to every month.
- The comma (,) : This operator specifies a list of values, for example: “1,5,10,15,20, 25”.
- The dash (-) : This operator specifies a range of values, for example: “5–15” days , which is equivalent to typing “5,6,7,8,9,….,13,14,15” using the comma operator.
- The separator (/) : This operator specifies a step value, for example: “0–23/” can be used in the hours field to specify command execution every other hour. Steps are also permitted after an asterisk, so if you want to say every two hours, just use */2.
How do I disable email output?
By default the output of a command or a script (if any produced), will be email to your local email account. To stop receiving email output from crontab you need to append >/dev/null 2>&1. For example:
0 3 * * * /root/backup.sh >/dev/null 2>&1
To mail output to particular email account let us say vivek@nixcraft.in you need to define MAILTO variable as follows:
MAILTO="vivek@nixcraft.in"
0 3 * * * /root/backup.sh >/dev/null 2>&1
See “Disable The Mail Alert By Crontab Command” for more information.
Task: List all your cron jobs
Type the following command:
# crontab -l
# crontab -u username -l
To remove or erase all crontab jobs use the following command:
# Delete the current cron jobs #
crontab -r
## Delete job for specific user. Must be run as root user ##
crontab -r -u username
The 5 places cron jobs are saved
Cron has been popular for decades because it's easy to use and available everywhere. The downside to this flexibility is that cron job maintenance and debugging can be a real headache. In this guide we explore five different places you can find cron jobs on your server.
The user crontab file
In Linux, each user has their own crontab that can be used to schedule jobs that will be run as that user. You can view, update and delete a user crontab file using the crontab command.
Viewing your user crontab
Viewing another user's crontab
If your server has a lot of users it could be challenging to find the right one. If you can see the job details in your cron logs, the username may be included. In the example below you can see the ubuntu user running the database backup script:
To update a user crontab, use crontab -e . The cron files themselves should not be updated directly. Using crontab -e will validate your changes and signal cron to reload your file.
The root user crontab
Like any other user, root has a user crontab. Essentially the same as any other user crontab, you are editing the root crontab when you run sudo crontab -e .
Jobs scheduled in the root user crontab will be executed as root with all of its privileges.
In /etc/cron.*
If your system has /etc/cron.hourly , /etc/cron.daily , /etc/cron.weekly , and /etc/cron.monthly directories, these can be used to schedule jobs by copying or symlinking a script or command.
In distributions like Ubuntu, you can see when these scripts will be invoked by looking for lines in /etc/crontab :
System crontab file
The original and still commonly used way to schedule system-wide cron jobs is by adding entries to the crontab file /etc/crontab .
Writing to /etc/crontab requires admin privileges and jobs scheduled here can be run as any user. To specify the user, provide a username as the first word after the schedule expression. In this example, the job will be run by user dataproc:
System drop-in directory /etc/cron.d
Another common way to schedule system-wide cron jobs is by adding a crontab file to /etc/cron.d .
Like jobs scheduled in /etc/crontab, writing to /etc/cron.d requires elevated privileges and the first word after the expression of each cron job must specify which user will run the job.
Tip: For installers and scripts, adding a file to /etc/cron.d is a much cleaner option than adding entries to crontab files.
Understanding /var/spool/cron
When individual user crontabs are edited using crontab -e , the crontab files themselves are stored in /var/spool/cron .
You can look, but avoid the temptation to edit crontab files here directly and always use crontab -e . If you edit files in /var/spool/cron directly you will lose the benefit of syntax checking that the crontab editor provides, and your changes will not be detected without sending a reload signal to the cron daemon.
Location of the crontab file
as many (most?) others, I edit my crontab via crontab -e , where I keep all routine operations such as incremental backup, ntpdate, various rsync operations, as well as making my desktop background christmas themed once a year. From what I’ve understood, on a fresh install or new user, this also automatically creates the file if it doesn’t exist. However, I want to copy this file to another user, so where is the actual file that I’m editing?
If this varies between distros, I’m using Centos5 and Mint 17
![]()
2 Answers 2
The location of cron files for individual users is /var/spool/cron/crontabs/ .
From man crontab :
Each user can have their own crontab, and though these are files in /var/spool/cron/crontabs , they are not intended to be edited directly.
heemayl is correct about the location of crontab files on Linux, but it might be different on other operating systems and «theoretically» is could also be in a different location on Linux. Essentially, when a special interface is provided to access the files, you should use it. This will ensure that cron gets to check the files before installing them, makes sure the files have the permissions it needs them to have, etc.
Therefore you should copy a crontab from one user to another using that interface, like this, not by accessing the files directly.