Unexpected exit code from sh scripts

When I execute a .sh script in actionscript or in sh script, I have the final command in the script to return an exit code. In this example, the execution of the script from bigfix cshould return an exit code of 231. However, it is returned as -25
image

At 15:27:02 +0000 - mailboxsite (http://xxx:52311/cgi-bin/bfgather.exe/mailboxsite3538126)
   Relevant - Custom Action (fixlet:8489392)
At 15:27:03 +0000 -
   ActionLogMessage: (action:8489392) Action signature verified for Execution
   ActionLogMessage: (action:8489392) starting action
   Report posted successfully
At 15:27:03 +0000 - actionsite (http://xxx:52311/cgi-bin/bfgather.exe/actionsite)
   Script ended (exit code = -25) (fixlet 8489392)
At 15:27:03 +0000 -
   ActionLogMessage: (action:8489392) ending action

The same thing happens when I use actionscript in the fixlet as opposed to sh script execution. During testing, I changed the exit code to 233 and the returned code was -23 so it seems like they are related. I’ve never seen this before, running BigFix Root 10.0.4.32 and BES client is 10.0.2.52.

Update: testing with a 10.0.2 client on Windows, actionscript exit code returns as expected:

image

   Relevant - Custom Action (fixlet:8495673)
At 19:00:22 +0000 - 
   ActionLogMessage: (action:8495673) Action signature verified for Execution
   ActionLogMessage: (action:8495673) starting action
At 19:00:22 +0000 - actionsite (http://xxxxx.com:52311/cgi-bin/bfgather.exe/actionsite)
   Command succeeded delete No 'C:\Program Files (x86)\BigFix Enterprise\BES Client\__BESData\actionsite\__createfile' exists to delete, no failure reported (action:8495673)
   Command succeeded delete No 'C:\Program Files (x86)\BigFix Enterprise\BES Client\__BESData\actionsite\test.bat' exists to delete, no failure reported (action:8495673)
   Command succeeded createfile until  (action:8495673)
   Command started - waithidden cmd.exe /c "copy /Y __createfile test.bat" (action:8495673)
At 19:00:22 +0000 - 
   Report posted successfully
At 19:00:22 +0000 - actionsite (http://xxxxx.com:52311/cgi-bin/bfgather.exe/actionsite)
   Command succeeded (Exit Code=0) waithidden cmd.exe /c "copy /Y __createfile test.bat" (action:8495673)
   Command started - waithidden cmd.exe /c "test.bat" (action:8495673)
At 19:00:23 +0000 - actionsite (http://xxxxx.com:52311/cgi-bin/bfgather.exe/actionsite)
   Command succeeded (Exit Code=231) waithidden cmd.exe /c "test.bat" (action:8495673)
At 19:00:23 +0000 - 
   ActionLogMessage: (action:8495673) ending action

231 + 25 = 256.

So is this being treated as a signed 8 bit value?

1 Like

Using a smaller exit code (23) works as expected for Linux:

   Relevant - Custom Action (fixlet:8552262)
At 13:24:43 +0000 -
   ActionLogMessage: (action:8552262) Action signature verified for Execution
   ActionLogMessage: (action:8552262) starting action
At 13:24:43 +0000 - actionsite (http://xxxxx:52311/cgi-bin/bfgather.exe/actionsite)
   Command succeeded delete __createfile (action:8552262)
   Command succeeded delete No '/var/opt/BESClient/__BESData/actionsite/test.sh' exists to delete, no failure reported (action:8552262)
   Command succeeded createfile until  (action:8552262)
   Command started - wait sh -c "cp __createfile test.sh" (action:8552262)
   Command succeeded (Exit Code=0) wait sh -c "cp __createfile test.sh" (action:8552262)
   Command started - wait sh -c "chmod a+x test.sh" (action:8552262)
   Command succeeded (Exit Code=0) wait sh -c "chmod a+x test.sh" (action:8552262)
   Command started - wait "./test.sh" (action:8552262)
At 13:24:44 +0000 - actionsite (http://xxxxx:52311/cgi-bin/bfgather.exe/actionsite)
   Command succeeded (Exit Code=23) wait "./test.sh" (action:8552262)
At 13:24:44 +0000 -
   ActionLogMessage: (action:8552262) ending action

I’ve found the following topic:
https://unix.stackexchange.com/questions/418784/what-is-the-min-and-max-values-of-exit-codes-in-linux

Relevant Sentence:
“Generally, you’d want to only use values 0 (generally meaning success) to 125 only”

It seems like this behavior is only on linux
could you please try exit code 125?

It works as expected when using a code 0 - 128.

The response from HCL support (case CS0264005).
When the Operating System Macro WEXITSTATUS(MAX_INT) for a UNIX client platform returns a value lower than 256 the return codes are casted to signed char (8 bit signed). so their range is -127 + 128 . when they are out this range, the casting to signed char can produce effects like the ones described. So, in order to be sure that the return codes reported by BESClient log are in sync with the ones actually returned back by the custom scripts they should be in the range -127 + 128 .

2 Likes