Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
sam_huang
Participant

API_scripts

Jump to solution

Hello everyone, I encountered a problem when using the API here. I hope to get help.

I call the API command in the gateway's Clish, and use mgmt login user (user_name) password (password) ip-address (address) in clish. But I add it to the script and use clish -c "mgmt login ip- address 192.168.10.252 user admin password ***" After running the script, I found that the login was not successful, and no error message was found in the message log file. Does any friend encounter this kind of problem?

 

0 Kudos
1 Solution

Accepted Solutions
PhoneBoy
Admin
Admin

Add this to the top of your script: source /opt/CPshrd-R80.40/tmp/.CPprofile.sh
(Replace R80.40 with your version) 
This will add mgmt_cli to the path so you can include it in your scripts.

View solution in original post

0 Kudos
8 Replies
PhoneBoy
Admin
Admin

I've never seen anyone call it that way before (i.e. using clish -c in a script).
Why aren't you using mgmt_cli instead, which can be called from a script?

0 Kudos
sam_huang
Participant

i know, but mgmt_cli Cannot be used in scheduled tasks

0 Kudos
PhoneBoy
Admin
Admin

Add this to the top of your script: source /opt/CPshrd-R80.40/tmp/.CPprofile.sh
(Replace R80.40 with your version) 
This will add mgmt_cli to the path so you can include it in your scripts.

View solution in original post

0 Kudos
sam_huang
Participant

OK, thank you very much, I will try

0 Kudos
sam_huang
Participant

I tried the method you said, adding at the top of bash:
source /opt/CPshrd-R81.10/tmp/.CPprofile.sh
I did not see the execution process in the message log file, but I saw the execution log in the Audit log.

Thank you for your answer

0 Kudos
_Val_
Admin
Admin

clish -c "...." is a single CLISH command called from bash. API calls will not work like that. To use API from bash and for scripts, do mgmt_cli, as @PhoneBoy already said.

0 Kudos
sam_huang
Participant

I need to make this action into a scheduled task. I tried to replace clish -c "mgmt" with mgmt_cli, but mgmt_cli will not be executed in the scheduled task

0 Kudos
Maxim_Tremblay
Participant

I use many scripts through the schedulers to run many Check Point tasks and it works well. Your problem is your CP environment is not loaded (Ex: $FWDIR, $PCDIR, etc. are missing) when you execute a CP program through your script. Add this line ". /etc/bashrc" (valid if you are running GAIA) in the top of your script. Example:

#!/bin/bash

. /etc/bashrc          # Load the Check Point environment if a GAIA (DOT space must be at the beginning of the line)

:

The rest of your script here

If my script is running on a SMB (ex 1400, 1500, etc.), I use: . /pfrm2.0/etc/bashrc

 

0 Kudos