Skip to content

Running custom scripts

Last updated on

  1. Use one of the following two command templates depending on your server OS:

    • RunShellScript (Linux)
    • RunPowerShellScript (Windows)
  2. Enter your custom script in the Script field of the pop up window on the right. The maximum length of your script content is 10.000 characters. You can also use the expanded script overview button for better code readability.

  3. Enter the arguments, if any. Separate multiple arguments with blank characters.

  4. Press Run.

Types of shell scripts that can be run on Linux

Section titled “Types of shell scripts that can be run on Linux”

For Linux there are different ways to run a shell script depending on whether an argument and/or a shebang header is present.

A script with both shebang header and arguments will be run as bash script.

Example script:

#!/bin/bash
# Display a simple message with arguments
echo "Hello, $1! This is a simple bash script with $2 arguments being used"

Arguments: Testuser two

Screenshot of the STACKIT Cloud Portal showing the "Expanded Script Overview" modal window on top of the command execution pane. Inside the modal window, a dark gray "Script" input block contains a multi-line bash script with a shebang header, highlighted with a red box. In the blurred background pane on the right, the "arguments" field is filled with "Testuser two" and is also highlighted with a red box.

Script with shebang header and no arguments

Section titled “Script with shebang header and no arguments”

A script with shebang header, but without arguments will be run with the given shebang interpreter.

Make sure the path to the interpreter in the shebang is correct when running the script via Run Command. In order to run i.e. a Python script like in the example below, Python needs to be properly installed on the server before you run the script.

Example script:

#!/bin/python3
# Display a simple message
print("Hello, world! This is a simple python script without arguments being used")

Screenshot of the STACKIT Cloud Portal showing the "Expanded Script Overview" modal window. Inside the dark gray text area, a Python script containing a python3 shebang header and a print statement is displayed. The blurred background execution pane on the right shows that the "arguments" field is left empty, the status is "Successful", and the "Output" section displays the printed message.

A script without shebang will be run as bash script.

Example script (displays system information):

Terminal window
echo "System Info: $(uname -a)"

Screenshot of the STACKIT Cloud Portal showing the "Expanded Script Overview" modal window. Inside the dark gray input area, a single-line command "echo 'System Info: $(uname -a)'" is entered. The blurred execution pane in the background on the right shows a "Successful" status and a system information string printed inside the "Output" area.

In this example we run a simple script to show a message with some arguments on a Windows Server.

Example script:

Terminal window
param (
[string]$arg1,
[string]$arg2
)
Write-Host "Hello, $arg1! This is a simple PowerShell script with $arg2 arguments being used"

Arguments: Testuser two

Screenshot of the STACKIT Cloud Portal showing the execution window for a custom PowerShell script on Windows. The "Expanded Script Overview" modal is open on the left, displaying a script with parameter blocks for arg1 and arg2, with the "Save" button highlighted by a red box. In the background pane on the right, red boxes highlight the external link icon next to "Script", the "arguments" input field containing "Testuser two", and the yellow "Run" button at the bottom.

The Output contains the desired result value with the arguments included:

Screenshot of the STACKIT Cloud Portal interface showing the successful results of the PowerShell script execution on a Windows VM. The status reads "Successful" in green, and the exit code is 0. At the bottom, the "Output" section is highlighted with a red box, displaying the greeting message formatted with the passed arguments.

In this example we run a simple “Hello World” script on a Linux Server:

Screenshot of the STACKIT Cloud Portal showing the execution of a custom script on a Linux VM. On the left side, the "RunShellScript" template is selected from the list and highlighted with a red box. On the right side, the details pane displays "echo 'Hello World!'" inside the "Script" field, and the yellow "Run" button at the bottom right is also highlighted with a red box.

Also here the Output contains the desired result value “Hello World!”:

Screenshot of the STACKIT Cloud Portal interface showing the successful result pane for the RunShellScript execution. The status displays "Successful" in green text, and the exit code is 0. At the bottom, the "Output" area is enclosed in a red box, displaying the printed result "Hello World!".