Getting the status of 'Linux needs restarting'

I am taking a two-step approach to getting the status of the ‘Linux needs restarting’ state. First, I run an action script to output the status to a file. Second I use and analysis to check the contents of the file. The action script does not work. It errors when I try to run the command line, either of two ways. I am running this on an Oracle Linux system.
These lines run fine:

delete __appendfile
appendfile dnf -needsrestarting -r > /var/log/RbtRqd.txt
wait chmod 555 "{(client folder of current site as string) & “/__appendfile”}

Then I’ve tried the lines below one at a time and either one fails, exit code 1:
wait “{(client folder of current site as string) & “/__appendfile”}”
wait "bash -c " & “{(client folder of current site as string) & “/__appendfile”}”

delete __appendfile
appendfile #!/bin/sh
appendfile dnf -needsrestarting -r

move __appendfile "{(client folder of current site as string) & "/script.sh"}"

wait chmod 555 "{(client folder of current site as string) & "/script.sh"}"
wait bash "{(client folder of current site as string) & "/script.sh"}"

That runs but I need to collect the output of the dnf command to a file. I changed it to appendfile dnf -needsrestarting -r > /var/log/RbtRqd.txt
and if fails on the move line. I added a line to delete the script file and the output file at the beginning and it ran.

delete __appendfile
appendfile #!/bin/sh
appendfile dnf -needsrestarting -r

move __appendfile "{(client folder of current site as string) & "/script.sh"}"
wait chmod 555 "{(client folder of current site as string) & "/script.sh"}"
wait bash "{(client folder of current site as string) & "/script.sh"}" >/var/log/RbtRqd.txt

This also works, at least the file is created…

delete “{(client folder of current site as string) & “/script.sh”}”
delete _appendfile
delete /var/log/RbtRqd.txt
appendfile #!/bin/sh
appendfile dnf needs-restarting -r > /var/log/RbtRqd.txt
move __appendfile “{(client folder of current site as string) & “/script.sh”}”
wait chmod 555 “{(client folder of current site as string) & “/script.sh”}”
wait bash “{(client folder of current site as string) & “/script.sh”}”

My analysis looks like this and it works:

if exists file “/var/log/RbtRqd.txt” then
(if exists lines whose (it contains “Reboot is required”) of file “/var/log/RbtRqd.txt” then “Reboot required” else “Reboot not required”)
else “file not found”

In my personal experience on RHEL using DNFs “restart required” is not 100% reliable, eg. Kernel updates did not set “restart required”.
Due to this we just add

action requires restart

in the fixlet running dnf command and bes property “pending restart” to report the status.

1 Like