Exit code 126 on running a shell script via Bigfix action

HI All, I am running a unix script by downloading it from Bigfix action and encountering the Exit code 126 on command mentioned below from Bigfix client logs, please suggest alternative:-1:

Command started - wait /bin/sh -c /tmp/LastPatchDateSuse.sh (action:573081)
** Command succeeded (Exit Code=126) wait /bin/sh -c /tmp/LastPatchDateSuse.sh (action:573081)**

Thank you

When you say unix - are u exexuting on linux Or aix server?

Suse Linux. I tried to copy the script and choose the option ‘sh’ to execute but it did not give the required output as running the script manually does. I also tried the other way of downloading it from uploads and executing it but…no go. The script is working fine manually.

When you test manually, are you invoking the same command as you are attempting via actionscript?

/bin/sh -c /tmp/LastPatchDateSuse.sh

No I an using ./LastPatchDateSuse.sh on the terminal.

Greetings.

The exit code points at a permissions issue on the script itself. I would double check that it is executable and then try again.

-Matt

Well, I downloaded the script in an action site successfully but not able to execute it. Would suggest a command to execute the shell script by making a new fixlet?

So far I have tried
Command started - wait bin/bash -c “/var/opt/BESClient/__BESData/actionsite/Last_date.sh” (action:573222
and
Command started - wait bin/bash -c “/var/opt/BESClient/__BESData/actionsite/Last_date.sh” (action:573222
But both have failed to execute.

You have two options.

  1. Copy the contents of the shell script and paste it into the Action Script, then specify script type ‘sh’.

  2. Copy the contents of the shell script and convert it to the native BigFix Action Script. You can do this here: https://www.bigfix.me/content/shelltoaction

-Matt

Thank you, I have the utility and have tried it but it does not solve the issue. There is a particular calculation in the script where bigfix is giving different output them manually running the script gives. We tried running the script through Bigfix with the said utility but could not get the correct output but when I executed the script manually on the server from actionsite, it just gave the correct output. looks strange, but we need to download the script in different action and execute with different action script.
So please suggest the command where we can execute the script by giving path of action site in which script is getting downloaded.

If possible, can you share the contents of the shell script?

Sure, please find the script:-1:
#!/bin/bash

export PATH=/sbin:/usr/sbin:/usr/bin:/bin:.
rm -f /tmp/pmoth
cat >> /tmp/pmoth << EOF
Apr,Jan
May,Feb
Jun,Mar
Jul,Apr
Aug,May
Sep,Jun
Oct,Jul
Nov,Aug
Dec,Sep
EOF

server_name="$(uname -n | cut -d. -f1)"
up_time=uptime | cut -d, -f1 | awk '{print $3,$4}'

uname -a > /tmp/uname-a

if grep default /tmp/uname-a
then
OS_type="SLES"
else
OS_type="RHEL"
fi

if [ $OS_type = “SLES” ]
then
OS_version=grep ^PRETTY_NAME /etc/os-release | cut -d'"' -f2
kernelv=awk '{print $3}' /tmp/uname-a | cut -d"-" -f1,2
last_patch_date=rpm -qa --last | grep ^kernel-default-$kernelv | awk '{print $2,$3,$4,$5,$6,$7,$8,$9}'
kernel_version=“kernel-default-$kernelv"
ptime=echo $last_patch_date | awk '{print $2,$3,$4,$5,$6}' > /tmp/ptime
pm=awk '{print $1}' /tmp/ptime
pd=awk '{print $2}' /tmp/ptime
py=awk '{print $NF}' /tmp/ptime
ctime=”$(date +%d\ %b\ %Y)"
echo “$ctime” > /tmp/ctime
cd1=awk '{print $1}' /tmp/ctime
cm=awk '{print $2}' /tmp/ctime
cy=awk '{print $3}' /tmp/ctime
mmatch=grep ^$cm /tmp/pmoth | cut -d"," -f2

if [ $py != “$cy” ] || [ $cm != “$mmatch” ]
then
Reporting_os_patching=Yes
else
Reporting_os_patching=No
fi
fi

if [ $OS_type = “RHEL” ]
then
OS_version=grep ^Red /etc/redhat-release
kernelv=awk '{print $3}' /tmp/uname-a | cut -d"-" -f1,2
last_patch_date=rpm -q --last kernel-$kernelv* | awk '{print $2,$3,$4,$5,$6,$7,$8,$9}'
kernel_version=“kernel-$kernelv"
ptime=echo $last_patch_date | awk '{print $2,$3,$4}' > /tmp/ptime
pd=awk '{print $1}' /tmp/ptime
pm=awk '{print $2}' /tmp/ptime
py=awk '{print $NF}' /tmp/ptime
ctime=”$(date +%d\ %b\ %Y)"
echo $ctime > /tmp/ctime
cd=awk '{print $1}' /tmp/ctime
cm=awk '{print $2}' /tmp/ctime
cy=awk '{print $3}' /tmp/ctime
mmatch=grep ^$cm /tmp/pmoth | cut -d"," -f2

if [ $py != “$cy” ] || [ $cm != “$mmatch” ]
then
Reporting_os_patching=Yes
else
Reporting_os_patching=No
fi
fi
echo “$server_name,$OS_version,$kernel_version,$last_patch_date,$Reporting_os_patching,$up_time” > /tmp/last-patchig-report.txt

if [ $OS_type = “RHEL” ]
then
k2=echo $last_patch_date | awk -F\ '{print $3 " " $2" " $4}'
k1=$(echo date +%b\ %d\ %Y)
else
k2=echo $last_patch_date | awk -F\ '{print $2 " " $3" " $5}'
k1=$(echo date +%b\ %d\ %Y)
fi
b=$k1
c=$k2
dt() {
d1=$(date -d “$b” +%s)
d2=$(date -d “$c” +%s)
a=echo $(( (d1 - d2) / 86400 )) days
}
dt
difference=echo "patch Difference day $a"

echo “$server_name,$OS_version,$kernel_version,$last_patch_date,$Reporting_os_patching,$up_time,$difference” > /tmp/last-patchig-report.txt

The script calculates the difference between the present and last patching day of servers and give output in a file with its os, kernel and other details. The last calculation mentioned below is not throwing the right output, don’t know why:-1:
b=$k1
c=$k2
dt() {
d1=$(date -d “$b” +%s)
d2=$(date -d “$c” +%s)
a=echo $(( (d1 - d2) / 86400 )) days
}
dt
difference=echo "patch Difference day $a"

if you store this on a suse and execute then you can get the right output but not from Bigfix action script.

Are you creating the script inside the bigfix action? The {} characters have special meaning as the start & end of a relevance substitution and need to be escaped when creating the script. Please post the Bigfix action and we can tell whether that is an issue.

Yes, please find my action script below:-1:
delete __createfile
createfile until end

#!/bin/bash

export PATH=/sbin:/usr/sbin:/usr/bin:/bin:.
rm -f /tmp/pmoth
cat >> /tmp/pmoth << EOF
Apr,Jan
May,Feb
Jun,Mar
Jul,Apr
Aug,May
Sep,Jun
Oct,Jul
Nov,Aug
Dec,Sep
EOF

server_name="$(uname -n | cut -d. -f1)"
up_time=uptime | cut -d, -f1 | awk '{{print $3,$4}'

uname -a > /tmp/uname-a

if grep default /tmp/uname-a
then
OS_type="SLES"
else
OS_type="RHEL"
fi

if [ $OS_type = “SLES” ]
then
OS_version=grep ^PRETTY_NAME /etc/os-release | cut -d'"' -f2
kernelv=awk '{{print $3}' /tmp/uname-a | cut -d"-" -f1,2
last_patch_date=rpm -qa --last | grep ^kernel-default-$kernelv | awk '{{print $2,$3,$4,$5,$6,$7,$8,$9}'
kernel_version=“kernel-default-$kernelv"
ptime=echo $last_patch_date | awk '{{print $2,$3,$4,$5,$6}' > /tmp/ptime
pm=awk '{{print $1}' /tmp/ptime
pd=awk '{{print $2}' /tmp/ptime
py=awk '{{print $NF}' /tmp/ptime
ctime=”$(date +%d\ %b\ %Y)"
echo “$ctime” > /tmp/ctime
cd1=awk '{{print $1}' /tmp/ctime
cm=awk '{{print $2}' /tmp/ctime
cy=awk '{{print $3}' /tmp/ctime
mmatch=grep ^$cm /tmp/pmoth | cut -d"," -f2

if [ $py != “$cy” ] || [ $cm != “$mmatch” ]
then
Reporting_os_patching=Yes
else
Reporting_os_patching=No
fi
fi

if [ $OS_type = “RHEL” ]
then
OS_version=grep ^Red /etc/redhat-release
kernelv=awk '{{print $3}' /tmp/uname-a | cut -d"-" -f1,2
last_patch_date=rpm -q --last kernel-$kernelv* | awk '{{print $2,$3,$4,$5,$6,$7,$8,$9}'
kernel_version=“kernel-$kernelv"
ptime=echo $last_patch_date | awk '{{print $2,$3,$4}' > /tmp/ptime
pd=awk '{{print $1}' /tmp/ptime
pm=awk '{{print $2}' /tmp/ptime
py=awk '{{print $NF}' /tmp/ptime
ctime=”$(date +%d\ %b\ %Y)"
echo $ctime > /tmp/ctime
cd=awk '{{print $1}' /tmp/ctime
cm=awk '{{print $2}' /tmp/ctime
cy=awk '{{print $3}' /tmp/ctime
mmatch=grep ^$cm /tmp/pmoth | cut -d"," -f2

if [ $py != “$cy” ] || [ $cm != “$mmatch” ]
then
Reporting_os_patching=Yes
else
Reporting_os_patching=No
fi
fi
echo “$server_name,$OS_version,$kernel_version,$last_patch_date,$Reporting_os_patching,$up_time” > /tmp/last-patchig-report.txt

if [ $OS_type = “RHEL” ]
then
k2=echo $last_patch_date | awk -F\ '{{print $3 " " $2" " $4}'
k1=$(echo date +%b\ %d\ %Y)
else
k2=echo $last_patch_date | awk -F\ '{{print $2 " " $3" " $5}'
k1=$(echo date +%b\ %d\ %Y)
fi
b=$k1
c=$k2
dt() {{
d1=$(date -d “$b” +%s)
d2=$(date -d “$c” +%s)
a=echo $(( (d1 - d2) / 86400 )) days
}
dt
difference=echo "patch Difference day $a"

echo “$server_name,$OS_version,$kernel_version,$last_patch_date,$Reporting_os_patching,$up_time,$difference” > /tmp/last-patchig-report.txt

end
delete Last_date.sh
copy __createfile Last_date.sh
wait chmod 555 Last_date.sh
wait bash Last_date.sh

The escapes look good, but the commands don’t match with the client logs you posted earlier. Try changing that last command to

wait /bin/bash -c Last_date.sh

Or

wait /bin/bash -c "{pathname of file "Last_date.sh" of client folder of current site}"

Should this be the format:-1:
Command succeeded (Exit Code=127)
wait /bin/bash -c “{/var/opt/BESClient/__BESData/actionsite/Last_date.sh}”

assuming the script is stored in above mentioned actionsite? If yes then I got the error code 127 on its execution.