[comment]: # ({843681e4-843681e4})
# 7 Scripts

[comment]: # ({/843681e4-843681e4})

[comment]: # ({931d02aa-931d02aa})
#### Overview

In the *Administration → Scripts* section user-defined global scripts
can be configured and maintained. Each script can be applied to
different hosts as needed. See also [Command
execution](/manual/appendix/command_execution).

The scripts, depending on the set user permissions, are available for
execution by clicking on the host in various frontend locations
(*Dashboard*, *Problems*, *Latest data*, *Maps*) and can also be run as
an action operation. The scripts are executed on the Zabbix server
(proxy) or agent.

Both on Zabbix agent and Zabbix proxy remote scripts are disabled by
default. They can be enabled by:

-   adding the `AllowKey=system.run[*]` parameter in agent
    configuration;
-   setting the EnableRemoteCommands parameter to '1' in proxy
    configuration (also in agent configuration before Zabbix 5.0.2)

A listing of existing scripts with their details is displayed.

![](../../../../../assets/en/manual/web_interface/scripts0.png){width="600"}

Displayed data:

|Column|Description|
|------|-----------|
|*Name*|Name of the script. Clicking on the script name opens the script [configuration form](scripts#configuring_a_global_script).|
|*Type*|Script type is displayed - *Script* or *IPMI* command.|
|*Execute on*|It is displayed whether the script will be executed on Zabbix server or agent.|
|*Commands*|All commands to be executed within the script are displayed.|
|*User group*|The user group that the script is available to is displayed (or *All* for all user groups).|
|*Host group*|The host group that the script is available for is displayed (or *All* for all host groups).|
|*Host access*|The permission level for the host group is displayed - *Read* or *Write*. Only users with the required permission level will have access to executing the script.|

To configure a new script, click on the *Create script* button in the
top right-hand corner.

[comment]: # ({/931d02aa-931d02aa})

[comment]: # ({44c45ea0-44c45ea0})
##### Mass editing options

A button below the list offers one mass-editing option:

-   *Delete* - delete the scripts

To use this option, mark the checkboxes before the respective scripts
and click on *Delete*.

[comment]: # ({/44c45ea0-44c45ea0})

[comment]: # ({aacbf6a8-aacbf6a8})
##### Using filter

You can use the filter to display only the scripts you are interested
in. For better search performance, data is searched with macros
unresolved.

The *Filter* link is available above the list of scripts. If you click
on it, a filter becomes available where you can filter scripts by name.

![](../../../../../assets/en/manual/web_interface/scripts_filter1.png){width="600"}

[comment]: # ({/aacbf6a8-aacbf6a8})

[comment]: # ({375e8ada-375e8ada})
#### Configuring a global script

![](../../../../../assets/en/manual/web_interface/script.png)

Script attributes:

|Parameter|Description|
|---------|-----------|
|*Name*|Unique name of the script.<br>Since Zabbix 2.2 the name can be prefixed with the desired path, for example, `Default/`, putting the script into the respective directory. When accessing scripts through the menu in monitoring sections, they will be organized according to the given directories.<br>A script cannot have the same name as an existing directory (and vice versa). A script name must be unique within its directory.<br>Unescaped script names are validated for uniqueness, i.e. "Ping" and "\\Ping" cannot be added in the same folder. A single backslash escapes any symbol directly after it. For example, characters '/' and '\\' can be escaped by backslash, i.e. \\/ or \\\\.|
|*Type*|Click the respective button to select script type - [IPMI command](/manual/config/notifications/action/operation/remote_command#ipmi_remote_commands) or Script.|
|*Execute on*|Click the respective button to execute the script on:<br>**Zabbix agent** - the script will be executed by Zabbix agent (if the system.run item is [allowed](/manual/config/items/restrict_checks)) on the host<br>**Zabbix server (proxy)** - the script will be executed by Zabbix server or proxy (if enabled by [EnableRemoteCommands](/manual/appendix/config/zabbix_proxy) - depending on whether the host is monitored by server or proxy<br>**Zabbix server** - the script will be executed by Zabbix server only|
|*Commands*|Enter full path to the commands to be executed within the script.<br><br>The following macros are supported:<br>host-related - {HOST.CONN}, {HOST.IP}, {HOST.DNS}, {HOST.HOST}, {HOST.NAME};<br>user-related - {USER.ALIAS}, {USER.FULLNAME}, {USER.NAME}, {USER.SURNAME};<br>custom [user macros](/manual/config/macros/user_macros).<br><br>*Notes:*<br>If a macro may resolve to a value with spaces (for example, host name), don't forget to quote as needed.<br>User-related macros are supported since Zabbix 5.0.2 to allow passing information about the user that launched the script. If the script was executed automatically under an action operation, these macros will not be resolved.|
|*Description*|Enter a description for the script.|
|*User group*|Select the user group that the script will be available to (or *All* for all user groups).|
|*Host group*|Select the host group that the script will be available for (or *All* for all host groups).|
|*Required host permissions*|Select the permission level for the host group - *Read* or *Write*. Only users with the required permission level will have access to executing the script.|
|*Enable confirmation*|Mark the checkbox to display a confirmation message before executing the script. This feature might be especially useful with potentially dangerous operations (like a reboot script) or ones that might take a long time.|
|*Confirmation text*|Enter a custom confirmation text for the confirmation popup enabled with the checkbox above (for example, *Remote system will be rebooted. Are you sure?*). To see how the text will look like, click on *Test confirmation* next to the field.<br><br>All macros supported for script commands are also supported for the confirmation text.<br>*Note:* the macros will not be expanded when testing the confirmation message.|

[comment]: # ({/375e8ada-375e8ada})

[comment]: # ({61456f7f-61456f7f})
#### Script execution and result

Scripts run by Zabbix server are executed by the order described in
[Command execution](/manual/appendix/command_execution) section
including exit code checking. The script result will be displayed in a
pop-up window that will appear after the script is run.

*Note:* The return value of the script is standard output together with
standard error.

See an example of a script and the result window below:

    uname -v
    /tmp/non_existing_script.sh
    echo "This script was started by {USER.ALIAS}"

![](../../../../../assets/en/manual/web_interface/frontend_sections/administration/scripts_result_1.png)

[comment]: # ({/61456f7f-61456f7f})

[comment]: # ({96d6e598-96d6e598})
#### Script timeout

[comment]: # ({/96d6e598-96d6e598})

[comment]: # ({0a96a89d-0a96a89d})
##### Zabbix agent

You may encounter a situation when a timeout occurs while executing a
script.

See an example of a script running on Zabbix agent and the result window
below:

![](../../../../../assets/en/manual/web_interface/frontend_sections/administration/script_timeout_1.png)

The error message, in this case, is the following:

    Timeout while executing a shell script.

In order to avoid such a situation, it is advised to optimize the script
itself (instead of adjusting Timeout parameter to a corresponding value
(in our case, > ‘5’) by modifying the [Zabbix agent
configuration](/manual/appendix/config/zabbix_agentd) and [Zabbix server
configuration](/manual/appendix/config/zabbix_server)).

In case still the Timeout parameter is changed in [Zabbix agent
configuration](/manual/appendix/config/zabbix_agentd) following error
message appears:

    Get value from agent failed: ZBX_TCP_READ() timed out.

It means that modification was made in [Zabbix agent
configuration](/manual/appendix/config/zabbix_agentd) and it is required
to modify Timeout setting also in [Zabbix server
configuration](/manual/appendix/config/zabbix_server).

[comment]: # ({/0a96a89d-0a96a89d})

[comment]: # ({3e43f3fc-3e43f3fc})
##### Zabbix server/proxy

See an example of a script running on Zabbix server and the result
window below:

![](../../../../../assets/en/manual/web_interface/frontend_sections/administration/script_timeout_3.png)

It is also advised to optimize the script itself (instead of adjusting
TrapperTimeout parameter to a corresponding value (in our case, >
‘11’) by modifying the [Zabbix server
configuration](/manual/appendix/config/zabbix_server)).

[comment]: # ({/3e43f3fc-3e43f3fc})
