Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
PhoneBoy
Admin
Admin
Jump to solution

mgmt_cli --sync false

Today, I learned of an option in mgmt_cli that might be useful in scripting contexts: --sync false.

According to the CLI help:

[--sync] {true|false}
        Synchronous execution of task - commands that generate the task will wait until the task is finished.
        Default {true}
        Environment variable: MGMT_CLI_SYNC

In practical terms, this suggests that for calls that would normally return a result right away, you'll get a task-id that can be monitored with show-task.
Where it is the most useful is in install-policy, which, when called with mgmt_cli, acts synchronously (i.e. does not complete until policy is installed). 

[Expert@MyMgmt:0]# mgmt_cli -r true install-policy policy-package "Standard" 

---------------------------------------------
Time: [11:17:54] 2/2/2026
---------------------------------------------

"Policy installation - Standard"  in progress  (40%) 
...

In investigating this issue further, though, I realized that install-policy returns a task-id by default if called via Web API.
I confirmed it using the below:

[Expert@MyMgmt:0]# curl_cli -k https://127.0.0.1/web_api/install-policy -H 'Content-Type: application/json' -H 'X-chkp-sid: my-session-id' --request POST -d ' { "policy-package" : "Standard" }'

{
 
 "task-id" : "b0c3cf65-b54f-4647-9c03-cf84077b32e1"
}

If I try to use --sync false with, say, run-script, you will get a "stuck" task that never completes until reboot:

[Expert@MyMgmt:0]# mgmt_cli -r true show-task task-id "f58349ae-4289-4f7c-b4ec-1c548be0a89a"
tasks:
- task-id: "f58349ae-4289-4f7c-b4ec-1c548be0a89a"
  task-name: "MyMgmt - Test"
  status: "in progress"
  progress-percentage: 10
  suppressed: false
  comments: "In Progress..."
...

Which suggests that --sync false is designed only for install-policy and might not work for other API calls.

@Omer_Kleinstern at the very least we might want to update the docs for mgmt_cli to mention it is actually synchronous with install-policy.

(1)
1 Solution

Accepted Solutions
Omer_Kleinstern
Employee
Employee

The switch "--sync" is supported on all API commands that return a task.

There is also the switch "--sync-frequency" for cases where the duration of the task is long and you want to reduce the number of show-task commands that run.

View solution in original post

5 Replies
the_rock
MVP Diamond
MVP Diamond

Good to know!

Best,
Andy
0 Kudos
PhoneBoy
Admin
Admin

I don't expect a lot of people to run into it either.
Having said that, in case someone asks again, it's now documented.

the_rock
MVP Diamond
MVP Diamond

You never know, definitely good to be aware.

Best,
Andy
0 Kudos
Omer_Kleinstern
Employee
Employee

The switch "--sync" is supported on all API commands that return a task.

There is also the switch "--sync-frequency" for cases where the duration of the task is long and you want to reduce the number of show-task commands that run.

PhoneBoy
Admin
Admin

As run-script is not an API call that returns a task-id, it explains the behavior.
Curious why run-script doesn't return a task-id as it would allow for longer-running scripts to be triggered via the API call.

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events