SOLVED How to setup a cronjob from the TrueNAS Scale CLI?

blanchet

Guru
Joined
Apr 17, 2018
Messages
516
Hi,

I would like to use the TrueNAS Scale CLI to create a cron job but I do not understand yet how to create a dictionary for the schedule.

For example, I would like to stop the SSH service at midnight

If I use an empty schedule, it creates a hourly job
Code:
task cron_job create description="stop ssh" enabled=true command="/usr/bin/systemctl stop ssh" user=root  schedule={}


But if I try to specify another schedule on the command line it always fails with Expected end of text, found 's'
Code:
task cron_job create description="stop ssh" enabled=true command="/usr/bin/systemctl stop ssh" user=root schedule={minute="0", hour="0"}

Expected end of text, found 's'
 description="stop ssh" enabled=true command="/usr/bin/systemctl stop ssh" user=root schedule={minute="0", hour="0"}


How can I specify the schedule dictionary?
 
Last edited:
Joined
Jun 2, 2019
Messages
591
Why are you trying to do it from the CLI? I don't think it will persist on upgrade or reboot. Use the GUI. (system, advanced, cron jobs)

You can put all the commands in a script, put the file on a data pool, and add execute permissions (chmod a+x)


Screen Shot 2021-12-22 at 10.07.32 AM.png
 
Last edited:

blanchet

Guru
Joined
Apr 17, 2018
Messages
516
I want to automate the setup of my TrueNAS Scale servers with the CLI.
Unlike TrueNAS Core, TrueNAS SCALE has a special CLI that uses the API so it is equivalent to the GUI and it is persistent.

I am still able to use many command of the CLI, except the dictionary of the schedule
 

pbartfai

Cadet
Joined
Mar 11, 2022
Messages
2
Try schedule parameter like the one bellow. It worked for me:

Code:
task cron_job create command="test.sh" enabled=true description="test" user=root schedule={"minute": "*/5", "hour": "*", "dom": "*", "month": "*", "dow": "*"}
 
Top