-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fallback solution for Last Reboot fact
openSUSE dont support "uptime --since", maybe others too, make a complicated one to save them all.
- Loading branch information
okopop
committed
Oct 23, 2024
1 parent
2ab3dc0
commit 6b76622
Showing
4 changed files
with
11 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
Facter.add(:motd_last_reboot) do | ||
# N.B. seconds can flip back and forth and create unwanted changes, skip them | ||
setcode do | ||
# This becomes empty when uptime command does not have "--since" implemented | ||
lastboot = Facter::Core::Execution.execute('/usr/bin/uptime --since') | ||
lastboot.slice(0..-4) # to 4th char from the end | ||
if !lastboot.empty? | ||
lastboot.slice(0..-4) # to 4th char from the end | ||
else | ||
# This is a solid fallback when uptime command does not work as expected | ||
Facter::Core::Execution.execute('date -d "@$(($(date +%s) - $(awk \'{print int($1)}\' /proc/uptime)))" +"%Y-%m-%d %H:%M"') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters