Exit Code not working

Hi,

Below is my script and i am trying to take exit code according to output.txt.

I am getting exit code and status as per my script but whenever output.txt contain 1 or 0 with any other numeric number(Example: 123, 4809,141,180) it is giving me success with exit code 0 instead of giving me exit code 100. Can anyone help me on this?

if {not exists folder "Error_Folder"}
run mkdir -p {parameter "Error_Folder"}
endif

delete __createfile


createfile until EOF
#!/bin/bash
tar -cvpzf /{parameter "Backup_Location"}/{parameter "Backup_File_Name"} {parameter "File_System_To_Exclude"} --one-file-system / &> /{parameter "Error_Folder"}/error.txt
echo $? > /{parameter "Error_Folder"}/output.txt
EOF

delete backup.sh
move __createfile backup.sh

wait /bin/sh "backup.sh"

parameter "file_content" = "{lines of file "output.txt" of folder (parameter "Error_Folder")}"
if {parameter "file_content" contains "0"}
elseif {parameter "file_content" contains "1"}
else
exit 100
endif
if {parameter "file_content" contains "0"}
elseif {parameter "file_content" contains "1"}
else
exit 100
endif

This is saying if the exist code has a 1 or a zero in it, return 0, otherwise return 100. So the behavior you’re describing makes total sense. This is because you’re saying does the exist code contain a zero or a 1: parameter "file_content" contains "1"

Try

if {parameter "file_content" = "0"}
elseif {parameter "file_content" = "1"}
else
exit 100
endif

Replacing contains with =

Thank you so much for the help that issue has been sorted out with your help. I am also facing issue with other script too.

I am using below script. Whenever true comes in any of the line then my exit code 100 never comes out. kindly help in this regards too.

parameter “file_content” = "{line 1 of file “output.txt” of folder (parameter “Error_Folder”)}"
if {parameter “file_content” = “False”}
Exit 100
elseif

parameter “file_content” = "{line 2 of file “output.txt” of folder (parameter “Error_Folder”)}"
if {parameter “file_content” = “False”}
Exit 100
endif
endif

You can’t treat parameters as variables, they are more like constants - once set they cannot be changed.

Direct update of your code

parameter “file_content1” = "{line 1 of file “output.txt” of folder (parameter “Error_Folder”)}"
if {parameter “file_content1” = “False”}
Exit 100
endif

parameter “file_content2” = "{line 2 of file “output.txt” of folder (parameter “Error_Folder”)}"
if {parameter “file_content2” = “False”}
Exit 100
endif

parameters can be useful for debugging (they appear in the client logs), but they don’t appear to be carrying information further into your script here, so, assuming you have already checked that the file and folder do exist:

if {(line 1 of it = "False" or line 2 of it = "False") of file "output.txt" of folder (parameter "Error_Folder")}
   exit 100
endif
1 Like