rahnev

Well-Known Member
Jul 6, 2016
56
7
8
Bulgaria
cPanel Access Level
Root Administrator
Hello all,
can somebody show me working example of hook, written in bash script? I want to do some custom actions when alias is created for example but cannot find a bash hook example. How can I catch input data and parse it by myself? I saw in documentation there is a template skeleton for php and perl.
Thanks in advance.
 

Anoop P Alias

Well-Known Member
Mar 31, 2015
103
15
18
Kochi,Kerala,India
cPanel Access Level
Root Administrator
the hook give you a json ds in stdin .Bash wont be a good choice to parse json. You can use python ,which is similar to bash or go with php/perl . Basically any high level language with support for stuff like json,yaml etc be good enough .
 

cPanelMichael

Technical Support Community Manager
Staff member
Apr 11, 2011
47,911
2,233
363
cPanel Access Level
DataCenter Provider
Twitter
Hello,

You can find the corresponding API function for a hook by enabling "Debug mode is on. The system displays information about every stage for every hookable event, even if no hooks exist for that stage." under the "Development" tab in "WHM >> Tweak Settings". Then, perform the specific action you want to hook into via cPanel or WHM, and watch the output in /usr/local/cpanel/logs/error_log.

For example, the following cPanel API 1 function is utilized when adding an Alias in cPanel:

Cpanel::Api1::Park::park

You can find documentation on hooks with cPanel functions at:

Guide to Standardized Hooks - Cpanel Functions - Software Development Kit - cPanel Documentation

As far as checking for conditions before a hook is ran, an example is documented at:

Guide to Standardized Hooks - Checks - Software Development Kit - cPanel Documentation

Thank you.
 

Anoop P Alias

Well-Known Member
Mar 31, 2015
103
15
18
Kochi,Kerala,India
cPanel Access Level
Root Administrator
Hi please find an example of a hook i wrote in python
raw.githubusercontent.com/AnoopAlias/XtendWeb/ndeploy4/scripts/cpanel_functions_hook_post.py

As mentioned before ..doing the same would be a bit tough in bash since bash does not support json. You may get some luck with text processing tools like sed or awk , but thats just a workaround and the easier way to do this would be using a high level language that support json. Perl,php,python,ruby etc would be easier here .
 
  • Like
Reactions: cPanelMichael