Introduction
Script hooks execute custom code before and after certain system-level operations.For example, script hooks can run before or after account creation, account modification, server software installation, or backup runs.
Warning:
This hook method is deprecated. To convert script hooks to use the Standardized Hooks system, use System or Whostmgr events in your Hook Action Code.
Basic usage
To create a script hook, perform the following steps:
- In any programming language, write a shell script to perform the desired actions.
- Data passes through script hooks via the
@ARGVarray. - The system always executes script hook scripts as the
rootuser.
- Data passes through script hooks via the
- Store the script in the
/usr/local/cpanel/scripts/directory.
Note:
Before you create a new script hook, check whether the hook exists in our list of available script hooks.
Convert @ARGV hashes
Because the system passes some script hooks to a hash through the @ARGV array, you must convert the @ARGV hash into a usable data structure.
Perl
To convert @ARGV into a usable data structure in Perl, assign it to a hash:
my %OPTS = @ARGV |
To access the data in the %OPTS hash, assign it to a variable:
my $username = $OPTS{'user'}; |
PHP
To convert @ARGV into a usable data structure in PHP, convert it into an associative array:
|
1
2
3
|
function argv2array ($argv) { $opts = array(); $argv0 = array_shift($argv); while(count($argv)) { $key = array_shift($argv); $value = array_shift($argv); $opts[$key] = $value; } return $opts; } |
Pass the $argv variable through the function to assign the data to the $opts variable:
$opts = argv2array($argv); |
To access the data in the $opts variable, you could use the following code:
$opts['user']; |
