Set Up Cronjobs#
Many tasks in i-doit can be automated via the i-doit console -- from rebuilding the search index to LDAP synchronization and JDisc imports. To ensure this happens reliably and without manual intervention, you set up cronjobs.
Recommendation
Setting up cronjobs is optionally but strongly recommended -- ideally right after installation. Without cronjobs, notifications are not sent, the search index becomes outdated, and incomplete objects accumulate.
How Does Cron Work?#
Cron is the standard scheduler on Linux. You define when a command should be executed -- and cron takes care of making it happen. Each line in the crontab has five time fields followed by the command:
1 2 3 4 5 6 7 | |
Common patterns:
| Cron expression | Meaning |
|---|---|
0 5 * * * | Daily at 05:00 |
*/15 * * * * | Every 15 minutes |
0 */2 * * * | Every 2 hours (on the hour) |
30 2 * * 1 | Every Monday at 02:30 |
0 3 1 * * | On the 1st of every month at 03:00 |
0 1 * * 1-5 | Monday through Friday at 01:00 |
Tip
Use crontab.guru to test cron expressions before deploying them.
The i-doit Console#
All automatable tasks run via console.php in the i-doit installation directory. The basic call looks like this:
1 2 | |
sudo -u www-data-- Execute as the web server user (important for file permissions)/var/www/html/-- Path to your i-doit installation (adjust as needed!)--user/--password-- An i-doit user with sufficient permissions--tenantId 1-- The tenant ID (always1for single-tenant setups)
Configuration files instead of long command lines
Instead of writing all parameters on the command line for every call, you can store them in an .ini file and reference it with --config or -c. This is more secure (no password in shell history) and cleaner -- especially for complex commands like ldap-sync or import-jdisc with many parameters.
1 | |
A detailed guide with examples for each command can be found at Configuration files for the i-doit console.
A complete list of all commands can be found at Commands and options.
Edit the Crontab#
Open the crontab of the web server user:
1 | |
Enter the desired jobs here. After saving, they become active immediately -- no restart required.
Recommended Cronjobs#
Essential Jobs (Daily)#
You should set up these jobs in every i-doit installation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
No passwords in the crontab
Instead of repeating --user and --password in every line, store the credentials in a configuration file and reference it with -c.
Mind the time window
Run jobs at night when no users are working. During execution, no other access to i-doit should occur -- neither via the web GUI nor via the API.
LDAP Synchronization#
If you synchronize users from an LDAP directory:
1 2 | |
--ldapServerId 1-- The ID of your LDAP server (found under Administration > LDAP)- The log is written to
/var/www/html/log/ldap-sync.log-- helpful for troubleshooting
The LDAP sync has many parameters (filters, mapping, groups). Instead of writing them all in the crontab, use a configuration file -- there you will find a complete example with attribute mapping and all options.
JDisc Import#
If you use JDisc Discovery for automatic inventory:
1 2 | |
--profile 1-- JDisc profile ID (found under Administration > Import > JDisc)--group 2-- JDisc server group--mode 4-- Import mode (4 = Update + Create)
CSV Import#
For recurring CSV imports:
1 2 | |
Report Export#
1 2 | |
Bundle All Jobs in a Script#
Instead of writing each command individually in the crontab, you can bundle all essential jobs in a bash script. This makes maintenance easier.
Script: idoit-jobs#
Create the script:
1 | |
Content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
Make it executable:
1 | |
Then only one line in the crontab:
1 | |
Script: idoit (Console Wrapper)#
If you frequently call console.php manually, a wrapper script helps:
1 | |
Content:
1 2 3 4 5 6 7 8 9 10 11 | |
1 | |
After that, you can call the console like this:
1 | |
Error Handling#
Errors Only via Email#
Set up an SMTP relay (e.g., with msmtp), then cronjobs will automatically report errors via email. Using the tool chronic from the moreutils package, only errors are reported -- successful runs remain silent:
1 2 3 4 5 | |
Check Log Files#
If a job fails, check the logs:
1 2 3 4 5 6 7 8 | |
Windows#
The bash scripts described here do not work on Windows. Create equivalent batch or PowerShell scripts and use the Windows Task Scheduler for automation. The console.php commands remain identical -- only the invocation differs:
1 | |
See also Automation and cronjobs on Windows.