Problem

Shell Jobs report the following error:

2021-11-25 18:48:33.147+01:00 [MAIN]    [End] [Error], errorState=failed, reason=failed, msg=java.io.IOException: 
Cannot run program "/var/sos-berlin.com/js7/agent/var_4445/work/script-12057651199840528744" 
(in directory "/var/sos-berlin.com/js7/agent/var_4445"): error=8, Exec format error, 
caused by: java.io.IOException: error=8, Exec format error

Analysis

  • The Unix OS does not know about the fact that the job script is in fact a script. Instead the job script is considered an executable file in ELF format. As the job script is not in ELF format the "Exec format error" is raised.
  • This situation can occur if the Unix OS is not configured to consider a default shell for shell scripts.
    • This problem has been reported e.g. for use with Alpine container images starting from 3.15 using Java 17.
  • Job scripts should specify the shell to be used by indicating a shebang in the first line of the script.

Solution

The solution includes adding a shebang to the first line of Shell jobs like this:

#!/bin/bash

echo "hello world"


The shebang specifies the interpreter that the job script is executed with, for example:

ShellShebangExplanation
Bourne Shell#!/bin/bashdirect reference to location of the bash executable

#!/usr/bin/env bashan alternative way to specify bash to be found from the PATH variable
General Shell#!/bin/shfrequently /bin/sh is set up as a symlink to the effective shell executable
PowerShell#!/user/bin/env pwshassumes the pwsh executable to be available from the PATH variable