sudo apt-get update
sudo apt-get install cron

# list the current cron jobs:
crontab -l

# edit cron jobs
crontab -e

# content examples...

# Every 2 minutes
*/2 * * * * pwsh -c "~\SCRIPT.ps1"

# Every day at 8pm minutes
0 20 * * * pwsh -c "~\SCRIPT.ps1"

# Every day at 8pm minutes (specifying no output)
0 20 * * * pwsh -c "~\SCRIPT.ps1" >/dev/null 2>&1

# Every 30 minutes (output to file)
*/30 * * * * pwsh -c "~\SCRIPT.ps1" > ~/cronlog.log

# Every 6 hours (output to email)
MAILTO="USERNAME@DOMAIN.com"

0 */6 * * * pwsh -c "~\SCRIPT.ps1"

# First of every month at midnight (output to file)
0 0 1 * * pwsh -c "~\SCRIPT.ps1" > ~/cronlog.log

# Noon on Saturday and Sunday (output to file)
0 12 * * 0,6 pwsh -c "~\SCRIPT.ps1" > ~/cronlog.log

# Note: If you have the PowerShell Cron module, you can use it as follows:
New-CronJob -Command 'pwsh -c "~\SCRIPT.ps1"' -Minute 2 | Out-Host 

Leave a Reply

Your email address will not be published. Required fields are marked *