---
title: "CAT in cron"
description: "Run a CAT test project on a schedule on Linux with cron — the PowerShell module under pwsh, the crontab line, the environment cron does not give you"
url: "https://docs.justcat.it/how-to-guides/pipelines-and-schedulers/cat-in-cron/"
---
# CAT in cron


## Before you start

cron is a scheduler and CAT recognizes it: an unattended run needs the **Enterprise plan** and a license key — from CAT 3.0 a cron job without the key stops before any test runs — see [Integrations](https://docs.justcat.it/reference/integrations/ "Integrations reference"). On Linux you can use **CAT CLI** or the **PowerShell module** (the Python module is Windows-only); this guide runs the module, so PowerShell 7 has to be installed per [Run CAT on Linux](https://docs.justcat.it/how-to-guides/licensing-and-admin/cat-on-linux/ "Run CAT on Linux") — with CAT CLI the crontab line calls `catcli run` instead and needs no `pwsh`. The providers built on Windows components — `Dax@*`, `PowerBI@*`, `CsvOleDB@1`, `ExcelOleDB@1` — are not available here; a cron job tests databases and files.

## Prepare the user

As the user whose crontab will run the job:

```bash
pwsh -Command "Install-Module CAT -RequiredVersion 3.0.0 -AcceptLicense -Force -Scope CurrentUser   # the version you tested with - pin it"
pwsh -Command "Set-CatInstance -LicenseKey '<key>'"      # stored in ~/.config/CAT/.catconfig of THIS user
```

## The script

cron runs commands with a minimal environment — no profile, no `~/.bashrc`, usually not even your `PATH`. Put everything the run needs into one script and source the variables there:

```powershell
# /opt/cat/run-dwh-tests.ps1
$ErrorActionPreference = 'Stop'
# the project file reads these as %DWH_CONNECTION_STRING% etc. - keep the real file readable by this user only
Get-Content /opt/cat/dwh.env | ForEach-Object { $n, $v = $_ -split '=', 2; [Environment]::SetEnvironmentVariable($n, $v) }
Import-Module CAT
Invoke-CatProject -Path /opt/cat/DWH/DwhTests.cat.yaml -LoggingLevel Error
$s = Get-CatTestResultSummary
if ($s.FailedCount + $s.ErrorCount -gt 0) { exit 1 }   # make the job's exit code say it
```

Run it once by hand as that user — `pwsh /opt/cat/run-dwh-tests.ps1` — before you schedule it. Variable names are case-sensitive on Linux; the project file must use exactly the casing of the `.env` file.

## The crontab line

`crontab -e` as that user:

```text
# every day at 06:15
15 6 * * * /usr/bin/pwsh -NoProfile -File /opt/cat/run-dwh-tests.ps1 >> /var/log/cat/dwh-tests.log 2>&1
```

Full paths everywhere — `which pwsh` tells you where it is — and a log redirect, because cron otherwise mails the output or drops it.

## Results

Give the project [outputs](https://docs.justcat.it/reference/outputs/introduction/ "Outputs") — JSON, YAML, JUnit or a [database table](https://docs.justcat.it/reference/outputs/database-outputs/ "Database outputs"); the Excel writer needs `libgdiplus` on Linux. The script above turns failed tests into exit code `1`, which is what a monitoring tool watching the cron job sees; CAT's own exit code, as everywhere, is `0` when the run completed — see [Results and exit codes](https://docs.justcat.it/reference/integrations/#results-and-exit-codes "Results and exit codes").

## Related

* [Run CAT on Linux](https://docs.justcat.it/how-to-guides/licensing-and-admin/cat-on-linux/ "Run CAT on Linux") — PowerShell 7 and the module on Ubuntu.
* [Integrations](https://docs.justcat.it/reference/integrations/ "Integrations reference") — plan, key, tool, secrets, results.
* [CAT in Windows Task Scheduler](https://docs.justcat.it/how-to-guides/pipelines-and-schedulers/cat-in-windows-task-scheduler/ "CAT in Windows Task Scheduler") — the same on Windows.

