Cron¶
Cron is a special program responsible for executing tasks at a predetermined time. Each user has a special crontab table where they can set up programs to run automatically.
DevilWEB¶
After logging in to the administrative panel, the Cron configuration can be found in the Cron jobs tab. By clicking the Edit button, a cron table will appear. On the right side of the entry, there is a button to enable or disable the entry, as well as a button to delete the task.

To add an entry, click + Add cron job and fill in the fields on the page. For example, the script /usr/home/LOGIN/script.sh will be run at 5:30 every Sunday.

Command line¶
Managing crontab tables is also possible from the command line using the crontab command:
crontab -l- shows the current cron tablecrontab -e- edits the tablecrontab -r- deletes the table
After running the crontab -e command, the table will be opened in the default editor. To change the default editor, change the EDITOR environment variable. For example, to change the default editor to nano, run the following command: echo 'export EDITOR=nano' >> $HOME/.bashrc && source $HOME/.bashrc. Adding export EDITOR=nano to the /usr/home/LOGIN/.bashrc file will cause the default editor to be permanently changed.
Examples¶
Here is an example crontab. Pay special attention to the PATH variable - it makes working with Cron more convenient.
# Use /usr/local/bin/bash to run commands. This line is not required for crontab to work.
SHELL=/usr/local/bin/bash
# Use the following value for the PATH variable. Without this, we must specify full paths to binaries
# (e.g. instead of python we must specify /usr/local/bin/python, etc.)
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/home/LOGIN/bin
# Run 5 minutes after midnight, every day
5 0 * * * /usr/home/LOGIN/bin/daily.job >> /usr/home/LOGIN/tmp/out 2>&1
# Run at 14:15 on the first day of every month -- output is
# mailed to the owner of the crontab
15 14 1 * * /usr/home/LOGIN/bin/monthly
# Annoy Stepan every weekday at 22:00
0 22 * * 1-5 echo "Stepan, it's 22:00. Where are your kids?!" | mail -s "It's 22:00" stepan@domain
# Send mail (daily at midnight)
0 0 * * * echo -e "Subject: Title of mail\n$x" | /usr/sbin/sendmail address@email
# Other examples
23 0-23/2 * * * echo "run 23 min after midnight, 2, 4, ..., every day"
5 4 * * sun echo "Run at 5 past 4 on Sundays"
0 10 * * 1,3 echo "Run every Monday and Wednesday at 10.00"
*/2 * * * * echo "Run every 2 minutes"
# Or using the verbal format using the "@" symbol, i.e.:
@reboot echo "System has been rebooted!"; # - command run every time the system is rebooted
@yearly echo "Another year has passed!"; # - equivalent to "0 0 1 1 *"
@annually echo "Another year has passed!"; # - same as above
@monthly echo "Another month has passed!"; # - equivalent to "0 0 1 * *"
@weekly echo "Another week has passed!"; # - equivalent to "0 0 * * 0"
@daily echo "Another day has passed!"; # - equivalent to "0 0 * * *"
@midnight echo "Another day has passed!"; # - same as above
@hourly echo "Another hour has passed!"; # - equivalent to "0 * * * *"
flock¶
For frequently executed tasks whose execution time cannot be easily predicted in advance, a situation may occur where another instance of the task is started before the previous one has finished. To prevent this, you can use the locking mechanism provided by the flock command.
flock uses a mechanism based on a shared lock file. When the command is started, a lock is placed on the specified file or directory. The lock is held for the duration of the command execution and released when the command finishes.
If another instance of flock is started at the same time and attempts to acquire a lock on the same file, it will wait by default until the lock is released. This ensures that the next execution of the task starts only after the previous one has finished.
Once the lock is released, one of the waiting processes can acquire it and start executing the specified command.
The file used as the lock file can be located anywhere. If the specified file does not exist, flock will create it automatically, provided that the user running the command has the required permissions.
Command syntax:
/usr/local/bin/flock [path_to_lock_file] [command_to_execute]
Example command:
/usr/local/bin/flock /home/accountlogin/flock1.lock /usr/bin/fetch --no-verify-hostname --no-verify-peer --user-agent="Devil2 CRON fetch" -o /dev/null https://mywebsite.com/cron.php