Undoubtedly, you could probably ask this question here and get a number of different answers. However, this method would pair with the notification script I referenced in the earlier post.
#/bin/bash
#
# Push Firewall Policies
#
# You need this in order to run the script as a cron job
source /opt/CPshrd-R80.30/tmp/.CPprofile.sh
#Log Into API
mgmt_cli login user <username> password <pw> > /home/admin/scripts/id.txt
# Push Policies
# If you only want to push the access policy portion:
mgmt_cli install-policy policy-package "<your policy package name>" access true -s /home/admin/scripts/id.txt > /home/admin/scripts/push_result.txt
cat /home/admin/scripts/push_result.txt |grep "Installation" > /home/admin/scripts/pushlog.txt
# If you want to push both Access Policy and Threat Prevention Policy, use this:
mgmt_cli install-policy policy-package "<your policy package name>" access true threat-prevention true -s /home/admin/scripts/id.txt > /home/admin/scripts/push_result.txt
cat /home/admin/scripts/push_result.txt |grep "Installation" >> /home/admin/scripts/pushlog.txt
# Log Out Of API
mgmt_cli logout -s /home/admin/scripts/id.txt
A couple of notes here,
1.) The source "/opt/CPshrd-R80.30/tmp/.CPprofile.sh" line needs to be modified to match the version of your management server.
2.) The output of the entire mgmt_cli command is captured in /home/admin/scripts/push_result.txt. Once it completes, I grep for "Installation" to single out the line from the output that indicates whether the installation Failed or Succeeded. I write the results of that to pushlog.txt.
The contends of this file are used in the notification script I referenced above. If you aren't looking to do any notifications, you can disregard all this and just focus on the mgmt_cli commands.
3.) If you are performing multiple policy installs in one script, I would make sure you change the output to ">>" so it appends to that file instead of overwriting it.
4.) Be sure to use full paths to files in scripts you intend to run under the task scheduler in GAIA or CRON. Its easy to forget to do this and suddenly things don't work as a scheduled task that worked when you ran it locally from some directory on the system.
5.) It is possible to create a user solely with Install Policy permissions. I created a specific user with those limited permissions as a little bit of a safeguard for this task.
Hope this helps!
R80 CCSA / CCSE