Posts RedHat VM last patched duration in days
Post
Cancel

RedHat VM last patched duration in days

  • current date in numeric
1
$ date +%s
  • get all installed patches with date and name in human redable form
1
$ rpm -qa --queryformat '%{installtime} %{installtime:date} %{name}\n'
  • get all installed patches with date and name in human redable form, sort it using installtime and return top record
1
$ rpm -qa --queryformat '%{installtime} %{installtime:date} %{name}\n' | sort | tail -n 1
  • get all installed patches installtime only, sort it using installtime and return top record
1
$ rpm -qa --queryformat '%{installtime}\n' | sort | tail -n 1
  • putting it all together and substracting dates
1
2
3
4
$ current_date=$(date +%s)
$ last_path_installed_date=$(rpm -qa --queryformat '%{installtime}\n' | sort | tail -n 1)
$ let last_patched=($current_date - $last_path_installed_date)/86400
$ echo $last_patched
This post is licensed under CC BY 4.0 by the author.