Bash script task
A bash script task will inject and execute the same bash script on several unix nodes concurrently.
This kind of task allows you to maintain the scripts of all your servers through a single interface.
This only works with Unix nodes.
Feel free to use the shebang to launch your script with the interpreter of your choice:
Bash script
#!/bin/bash echo "Hello!"Python script
#!/usr/bin/env python3 -u print("Hello!")Powershell script
#!/usr/bin/env powershell Write-Host "hello!"PHP script
#!/usr/bin/php <?php echo "Hello!";Perl script
#!/usr/bin/perl print("Hello!")
Using project constants
Project constants can be used in the script content as environment variables prefixed with CPC_ (for CTFreak Project Constant).
Here’s an example using a project constant named NUMBER_OF_RETENTION_DAYS:
#!/bin/bash
echo "Delete backup files older than $CPC_NUMBER_OF_RETENTION_DAYS days"
…
If you later decide to increase the retention period of your backups, you’ll only need to modify the constant value to affect all cleanup scripts referring to it.
Using task parameters
Like project constants, task parameters can be used in the script content as environment variables prefixed with CTP_ (for CTFreak Task Parameter).
Here’s an example using a text task parameter named FIRST_NAME:
#!/bin/bash
echo "Hello $CTP_FIRST_NAME !"
Task parameters values are converted to text format when assigned to an environment variable.
The following conversion rules are applied according to parameter type:
- Checkbox → Checked:
true, Unchecked:false - Date → Formatting with the
YYYY-MM-DDpattern - Selector, Integer and Text → No specific formatting
Task characteristics
In addition to the common task characteristics, here are those specific to bash script tasks.
Node Set filter
Filter (by names and tags) the nodes on which the script will be executed.
NB: This filter is combined with the filter applied at the project level.
Max. number of concurrent node executions
When a script is executed on several nodes, you can specify the maximum number of nodes to be processed concurrently.
Max. number of script execution retries
Maximum number of retry attempts if the script execution fails on a node. Defaults to 0 (no retry).
Delay between retries
Delay in seconds between retry attempts. Defaults to 0 (immediate retry).
Log output
Controls when node execution logs are retained:
- Always – logs are kept for every execution
- On failure or abort – logs are kept only when the execution fails or is aborted
- Never – logs are discarded