Need to excute a script in action to find last patch date of suse servers

HI I have the below mentioned shell script which is working locally on suse servers to fetch the ‘last patch date’.

#!/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

Action Script:-1:

//Shell to Action Script Conversion Utility
delete __appendfile

appendfile #!/bin/bash
appendfile #
appendfile export PATH=/sbin:/usr/sbin:/usr/bin:/bin:.
appendfile rm -f /tmp/pmoth
appendfile cat >> /tmp/pmoth << EOF
appendfile Apr,Jan
appendfile May,Feb
appendfile Jun,Mar
appendfile Jul,Apr
appendfile Aug,May
appendfile Sep,Jun
appendfile Oct,Jul
appendfile Nov,Aug
appendfile Dec,Sep
appendfile EOF
appendfile #
appendfile server_name="$(uname -n | cut -d. -f1)"
appendfile up_time=uptime | cut -d, -f1 | awk '{print $3,$4}'
appendfile
appendfile uname -a > /tmp/uname-a
appendfile
appendfile if grep default /tmp/uname-a
appendfile then
appendfile OS_type="SLES"
appendfile else
appendfile OS_type="RHEL"
appendfile fi
appendfile
appendfile if [ $OS_type = “SLES” ]
appendfile then
appendfile OS_version=grep ^PRETTY_NAME /etc/os-release | cut -d'"' -f2
appendfile kernelv=awk '{print $3}' /tmp/uname-a | cut -d"-" -f1,2
appendfile last_patch_date=rpm -qa --last | grep ^kernel-default-$kernelv | awk '{print $2,$3,$4,$5,$6,$7,$8,$9}'
appendfile kernel_version=“kernel-default-$kernelv"
appendfile ptime=echo $last_patch_date | awk '{print $2,$3,$4,$5,$6}' > /tmp/ptime
appendfile pm=awk '{print $1}' /tmp/ptime
appendfile pd=awk '{print $2}' /tmp/ptime
appendfile py=awk '{print $NF}' /tmp/ptime
appendfile ctime=”$(date +%d\ %b\ %Y)"
appendfile echo “$ctime” > /tmp/ctime
appendfile cd1=awk '{print $1}' /tmp/ctime
appendfile cm=awk '{print $2}' /tmp/ctime
appendfile cy=awk '{print $3}' /tmp/ctime
appendfile mmatch=grep ^$cm /tmp/pmoth | cut -d"," -f2
appendfile #
appendfile if [ $py != “$cy” ] || [ $cm != “$mmatch” ]
appendfile then
appendfile Reporting_os_patching=Yes
appendfile else
appendfile Reporting_os_patching=No
appendfile fi
appendfile fi
appendfile
appendfile if [ $OS_type = “RHEL” ]
appendfile then
appendfile OS_version=grep ^Red /etc/redhat-release
appendfile kernelv=awk '{print $3}' /tmp/uname-a | cut -d"-" -f1,2
appendfile last_patch_date=rpm -q --last kernel-$kernelv* | awk '{print $2,$3,$4,$5,$6,$7,$8,$9}'
appendfile kernel_version=“kernel-$kernelv"
appendfile ptime=echo $last_patch_date | awk '{print $2,$3,$4}' > /tmp/ptime
appendfile pd=awk '{print $1}' /tmp/ptime
appendfile pm=awk '{print $2}' /tmp/ptime
appendfile py=awk '{print $NF}' /tmp/ptime
appendfile ctime=”$(date +%d\ %b\ %Y)"
appendfile echo $ctime > /tmp/ctime
appendfile cd=awk '{print $1}' /tmp/ctime
appendfile cm=awk '{print $2}' /tmp/ctime
appendfile cy=awk '{print $3}' /tmp/ctime
appendfile mmatch=grep ^$cm /tmp/pmoth | cut -d"," -f2
appendfile #
appendfile if [ $py != “$cy” ] || [ $cm != “$mmatch” ]
appendfile then
appendfile Reporting_os_patching=Yes
appendfile else
appendfile Reporting_os_patching=No
appendfile fi
appendfile fi
appendfile echo “$server_name,$OS_version,$kernel_version,$last_patch_date,$Reporting_os_patching,$up_time” > /tmp/last-patchig-report.txt
appendfile #
appendfile

//modify appendfile to allow execution
wait chmod 555 "{(client folder of current site as string) & “/__appendfile”}

//execute shell script as written
wait “{(client folder of current site as string) & “/__appendfile”}”

But the action is failing on the below line where shell script is declaring variable, please check below and advise updation in action script:-1:

Completed //Shell to Action Script Conversion Utility
Completed delete __appendfile
Completed appendfile #!/bin/bash
Completed appendfile #
Completed appendfile export PATH=/sbin:/usr/sbin:/usr/bin:/bin:.
Completed appendfile rm -f /tmp/pmoth
Completed appendfile cat >> /tmp/pmoth << EOF
Completed appendfile Apr,Jan
Completed appendfile May,Feb
Completed appendfile Jun,Mar
Completed appendfile Jul,Apr
Completed appendfile Aug,May
Completed appendfile Sep,Jun
Completed appendfile Oct,Jul
Completed appendfile Nov,Aug
Completed appendfile Dec,Sep
Completed appendfile EOF
Completed appendfile #
Completed appendfile server_name="$(uname -n | cut -d. -f1)"
Failed appendfile up_time=uptime | cut -d, -f1 | awk '{print $3,$4}'
appendfile
appendfile uname -a > /tmp/uname-a
appendfile
appendfile if grep default /tmp/uname-a
appendfile then
appendfile OS_type="SLES"
appendfile else
appendfile OS_type="RHEL"
appendfile fi
appendfile
appendfile if [ $OS_type = “SLES” ]
appendfile then
appendfile OS_version=grep ^PRETTY_NAME /etc/os-release | cut -d'"' -f2
appendfile kernelv=awk '{print $3}' /tmp/uname-a | cut -d"-" -f1,2
appendfile last_patch_date=rpm -qa --last | grep ^kernel-default-$kernelv | awk '{print $2,$3,$4,$5,$6,$7,$8,$9}'
appendfile kernel_version=“kernel-default-$kernelv"
appendfile ptime=echo $last_patch_date | awk '{print $2,$3,$4,$5,$6}' > /tmp/ptime
appendfile pm=awk '{print $1}' /tmp/ptime
appendfile pd=awk '{print $2}' /tmp/ptime
appendfile py=awk '{print $NF}' /tmp/ptime
appendfile ctime=”$(date +%d\ %b\ %Y)"
appendfile echo “$ctime” > /tmp/ctime
appendfile cd1=awk '{print $1}' /tmp/ctime
appendfile cm=awk '{print $2}' /tmp/ctime
appendfile cy=awk '{print $3}' /tmp/ctime
appendfile mmatch=grep ^$cm /tmp/pmoth | cut -d"," -f2
appendfile #
appendfile if [ $py != “$cy” ] || [ $cm != “$mmatch” ]
appendfile then
appendfile Reporting_os_patching=Yes
appendfile else
appendfile Reporting_os_patching=No
appendfile fi
appendfile fi
appendfile
appendfile if [ $OS_type = “RHEL” ]
appendfile then
appendfile OS_version=grep ^Red /etc/redhat-release
appendfile kernelv=awk '{print $3}' /tmp/uname-a | cut -d"-" -f1,2
appendfile last_patch_date=rpm -q --last kernel-$kernelv* | awk '{print $2,$3,$4,$5,$6,$7,$8,$9}'
appendfile kernel_version=“kernel-$kernelv"
appendfile ptime=echo $last_patch_date | awk '{print $2,$3,$4}' > /tmp/ptime
appendfile pd=awk '{print $1}' /tmp/ptime
appendfile pm=awk '{print $2}' /tmp/ptime
appendfile py=awk '{print $NF}' /tmp/ptime
appendfile ctime=”$(date +%d\ %b\ %Y)"
appendfile echo $ctime > /tmp/ctime
appendfile cd=awk '{print $1}' /tmp/ctime
appendfile cm=awk '{print $2}' /tmp/ctime
appendfile cy=awk '{print $3}' /tmp/ctime
appendfile mmatch=grep ^$cm /tmp/pmoth | cut -d"," -f2
appendfile #
appendfile if [ $py != “$cy” ] || [ $cm != “$mmatch” ]
appendfile then
appendfile Reporting_os_patching=Yes
appendfile else
appendfile Reporting_os_patching=No
appendfile fi
appendfile fi
appendfile echo “$server_name,$OS_version,$kernel_version,$last_patch_date,$Reporting_os_patching,$up_time” > /tmp/last-patchig-report.txt
appendfile #
appendfile
//modify appendfile to allow execution
wait chmod 555 "{(client folder of current site as string) & “/__appendfile”}
//execute shell script as written
wait “{(client folder of current site as string) & “/__appendfile”}”

Please suggest on this.

The problem is that curly braces have a special meaning in BigFix Actionscript (relevance substitution). You’ll have to escape the curly braces: http://www-01.ibm.com/support/docview.wss?uid=swg21506259

1 Like

Thanks for your response, I referred to the article mentioned and tried to substitute the braces and it failed again, I tired as below:-1:
appendfile up_time=‘uptime | cut -d, -f1 | awk “{print $3,$4}”’

Please suggest correct substitution.

appendfile up_time=‘uptime | cut -d, -f1 | awk "{{print $3,$4}"’

2 Likes

Thank a ton!!:blush: