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.