Improved CheckKernel.sh based on /etc/os-releases and updated README

This commit is contained in:
Ulf 2021-11-02 21:15:13 +01:00
parent ca37f9ff4c
commit e18bc5ab5c
2 changed files with 53 additions and 45 deletions

View file

@ -2,20 +2,15 @@
# CheckKernel checks if Kernel was updated and not aktivated (rebooted) # CheckKernel checks if Kernel was updated and not aktivated (rebooted)
# #
# (c) GPL by Ulf Bartholomäus ub1x@gmx.net # (c) GPL by Ulf Bartholomäus ub1x@gmx.net
VERSION="$( basename $0 ) Version 0.2.3 from 12.7.2021" VERSION="$( basename $0 ) Version 0.2.4 from 02.11.2021"
# #
# Input: 1 parameter optional ("-d" = debug and "-v" = verbose / "-D" = Distro only / "-K" = running KernelVerion / "-N" = New Kernel Version) # Input: 1 parameter optional ("-d" = debug and "-v" = verbose / "-D" = Distro only / "-DV" = Distro and release only / "-K" = running KernelVerion / "-N" = New Kernel Version)
# Output: text messages and a kdialog if this is installed # Output: text messages and a kdialog if this is installed
# Returnvalue: 0 if Kernel OK and 10 if Kernel is changed # Returnvalue: 0 if Kernel OK and 10 if Kernel is changed
# #
# ToDo: Check if initrd and vmlinuz exists
# cat /etc/issue
# cat /proc/version
# Error: inxi - hangs in a script:
# MyDistro="$( eval inxi -xSz | grep Distro: | awk -F'Distro: ' '{print $2}' )"
# https://github.com/smxi/inxi/issues/181
# #
# Changes: # Changes:
# 0.2.4: Change way to collect Distro Name from /etc/os-releas (if empty - provide old info)
# 0.2.3: Fix error => update in case only one Kernel is avaialble # 0.2.3: Fix error => update in case only one Kernel is avaialble
# 0.2.2: Fix error => new Kernel update: replace initrd with vmlinuz check # 0.2.2: Fix error => new Kernel update: replace initrd with vmlinuz check
# 0.2.1: added -D -K and -N option # 0.2.1: added -D -K and -N option
@ -23,12 +18,12 @@ VERSION="$( basename $0 ) Version 0.2.3 from 12.7.2021"
# 0.2.0: InitKernel und VmlzKernel entfernt, # 0.2.0: InitKernel und VmlzKernel entfernt,
# [ $( ls -1 /boot/ | grep initrd- | wc -l ) -gt 1 ] && echo "** Error" || ls -1 /boot/ | grep initrd- | cut -d '-' -f 2,3,4 # [ $( ls -1 /boot/ | grep initrd- | wc -l ) -gt 1 ] && echo "** Error" || ls -1 /boot/ | grep initrd- | cut -d '-' -f 2,3,4
# Some small changes and simplifications # Some small changes and simplifications
# 0.1.9: NewKernel erneut angepasstsys # 0.1.9: InitKernel erneut angepasstsys
# 0.1.8: "==" -> "=" sowie kleinere Shönheitskorrekturen - sowie NewKernel mit awk statt cut # 0.1.8: "==" -> "=" sowie kleinere Shönheitskorrekturen - sowie InitKernel mit awk statt cut
# 0.1.7: remove "CheckKernel.sh: Zeile 33: lsb_release: Kommando nicht gefunden." # 0.1.7: remove "CheckKernel.sh: Zeile 33: lsb_release: Kommando nicht gefunden."
# and => -d = debaug # and => -d = debaug
# 0.1.6: if "lsb_release" not available use "cat /etc/*-release" info # 0.1.6: if "lsb_release" not available use "cat /etc/*-release" info
# 0.1.5: Fix trouble if NewKernel is empty # 0.1.5: Fix trouble if InitKernel is empty
# 0.1.4: Fix some errors # 0.1.4: Fix some errors
# 0.1.3: Fix running and new kernel are equal but shown as different # 0.1.3: Fix running and new kernel are equal but shown as different
# 0.1.2: Remove "initrd-" from InitKernel # 0.1.2: Remove "initrd-" from InitKernel
@ -44,11 +39,11 @@ VERSION="$( basename $0 ) Version 0.2.3 from 12.7.2021"
# 0.0.1: generation # 0.0.1: generation
# #
DEBUG="" DEBUG="" # Debug mode ="1"
MyDistro="" MyDistro="" # Name of the Distro
MyKernel="" MyDstVer="" # Distro Version info
NewKernel="" MyKernel="" # Running Kernel Version
InitKernel="" InitKernel="" # Newest Kernel at initrd
if [ $# -gt 0 ] && [ "$1" = "-d" ] ; then if [ $# -gt 0 ] && [ "$1" = "-d" ] ; then
DEBUG="1" DEBUG="1"
@ -56,16 +51,38 @@ if [ $# -gt 0 ] && [ "$1" = "-d" ] ; then
shift shift
fi fi
MyDistro="$( cat /proc/version )" if [ -e /etc/os-release ]; then
MyDistro="${MyDistro/*;/}" # remove first string till ";" MyDistro="$( grep PRETTY_NAME /etc/os-release )"
MyDistro="${MyDistro/)*/}" # remove anything behind ")" MyDistro="${MyDistro/*=\"/}" # remove first string till ="
MyDistro="${MyDistro/# /}" # remove blanks in the beginning MyDistro="${MyDistro/\"*/}" # remove "
MyDstVer="$( grep VERSION_ID /etc/os-release )"
MyDstVer="${MyDstVer/*=\"/}" # remove first string till ="
MyDstVer="(${MyDstVer/\"*/})" # remove "
fi
if [ -z "${MyDistro}" ] && [ -e /proc/version ]; then
MyDistro="$( cat /proc/version )"
MyDistro="${MyDistro/*;/}" # remove first string till ";"
MyDistro="${MyDistro/)*/}" # remove anything behind ")"
MyDistro="${MyDistro/# /}" # remove blanks in the beginning
echo -n "Version ${MyDistro} | "
fi
if [ $# -gt 0 ] && [ "$1" = "-D" ] ; then if [ $# -gt 0 ] && [ "$1" = "-D" ] ; then
echo "${MyDistro}" echo "${MyDistro}"
exit exit
fi fi
if [ $# -gt 0 ] && [ "$1" = "-DV" ] ; then
echo "${MyDistro} ${MyDstVer}"
exit
fi
if [ $# -gt 0 ] && [ "$1" = "-V" ] ; then
echo "${MyDstVer}"
exit
fi
MyKernel="$( uname -r )" MyKernel="$( uname -r )"
if [ $# -gt 0 ] && [ "$1" = "-K" ] ; then if [ $# -gt 0 ] && [ "$1" = "-K" ] ; then
@ -74,43 +91,32 @@ if [ $# -gt 0 ] && [ "$1" = "-K" ] ; then
fi fi
InitKernel="$( ls -1tr /boot/ | grep 'vmlinuz-' )" InitKernel="$( ls -1tr /boot/ | grep 'vmlinuz-' )"
if [ $( echo "${InitKernel}" | wc -l ) -ge 1 ] ; then if [ -n "${InitKernel}" ] ; then
# If To much Kernels - exit InitKernel="${InitKernel/*vmlinuz-/}"
# use only the last listed kernel (hopfully the newest)
NewKernel="${InitKernel/*vmlinuz-/}"
else
# no "vmlinuz" entry
[ ${DEBUG} ] && echo "** Error: /boot/vmlinuz-* is missing <${InitKernel}>"
# exit 10
NewKernel="Missing /boot/vmlinuz-*"
fi fi
if [ $# -gt 0 ] && [ "$1" = "-N" ] ; then if [ $# -gt 0 ] && [ "$1" = "-N" ] ; then
echo "${NewKernel}" echo "${InitKernel}"
exit exit
fi fi
if [ ${DEBUG} ] ; then
echo -e "* Debug Info *\n\t MyDistro=${MyDistro},\n\t MyKernel=${MyKernel},\n\t InitKernel=${InitKernel},\n\t NewKernel=${NewKernel}!"
[ "x${MyKernel}" = "x${NewKernel}" ] && echo -e "*\t(${MyKernel}) = (${NewKernel})" || echo -e "***\t(${MyKernel}) != ${NewKernel} !!!"
echo "*"
fi
if [ "x${MyKernel}" = "x${NewKernel}" ] ; then if [ "${MyKernel}" = "${InitKernel}" ] ; then
if [ $# -gt 0 ] && [ "$1" = "-v" ] ; then if [ $# -gt 0 ] && [ "$1" = "-v" ] ; then
echo -e "\t*** Distro: ${MyDistro} \tKernel ${MyKernel} \t$( date "+%X / %d.%m.%Y" ) \t*** Kernel OK ***" echo -e "\t*** $( date "+%X / %d.%m.%Y" ) \tDistro: ${MyDistro} ${MyDstVer} \tKernel: ${MyKernel} \t*** Kernel OK ***"
else else
echo "*** Kernel OK (${MyKernel})"; echo "*** Kernel OK (${MyKernel})";
fi fi
else else
if ( [ $# -gt 0 ] && [ "$1" == "-v" ] ) ; then if ( [ $# -gt 0 ] && [ "$1" = "-v" ] ) ; then
echo -e "\t*** Distro: ${MyDistro} \tKernel ${MyKernel} \t$( date "+%X / %d.%m.%Y" ) \t*** NEW Kernel ${NewKernel}!!! ***" echo -e "\t*** $( date "+%X / %d.%m.%Y" ) \tDistro: ${MyDistro} ${MyDstVer} \tKernel: ${MyKernel} \t*** NEW Kernel ${InitKernel}!!! ***"
else else
MsgTxt="*** Kernel Updated from ${MyKernel} to ${NewKernel}! => please reboot" MsgTxt="*** Kernel Updated from ${MyKernel} to ${InitKernel}! => please reboot"
echo "${MsgTxt}"; echo "${MsgTxt}";
logger -t $( basename $0 ) "${MsgTxt}" logger -t $( basename $0 ) "${MsgTxt}"
if [ $# -eq 0 ] && [ -e $( which kdialog 2>> /dev/null ) ] ; then if [ $# -eq 0 ] && [ -e $( which kdialog 2>> /dev/null ) ] ; then
kdialog --title "*** $( hostname ) ***" --error "${MsgTxt}" >> /dev/null 2>> /dev/null kdialog --title "*** $( hostname ) ***" --error "${MsgTxt}" >> /dev/null 2>> /dev/null
fi fi
fi fi
exit 10
fi fi

View file

@ -9,12 +9,14 @@ See also at [LUG-VS-Wiki Nützliche Scripte](https://lug-vs.org//lugvswiki/index
|Script|Description| |Script|Description|
|---|---| |---|---|
|[CheckKernel.sh](CheckKernel.sh)|Show some Kernel information (supports -d for debug und -v for verbose)|
|[dfc.sh](dfc.sh)|Script shows the free memory of all mounted file systems beside *tmpfs traffic light colored|
|[duc-index.sh](duc-index.sh)|Script to be added e.g. as cronjob, which generate an index w/o NFS and DavFS file system mounted files| |[duc-index.sh](duc-index.sh)|Script to be added e.g. as cronjob, which generate an index w/o NFS and DavFS file system mounted files|
|[dfc.sh](dfc.sh)|Script shows the free memory of all mounted file systems beside *tmpfs|
|[make_exif-name.sh](make_exif-name.sh)|Add a comment in all *.jpg files in the actual and all subfolders| |[make_exif-name.sh](make_exif-name.sh)|Add a comment in all *.jpg files in the actual and all subfolders|
|[write-exif-comment.sh](write-exif-comment.sh)|Write JPEG EXIF comment in all *.jpg files| |[SavePC.sh](SavePC.sh)|Save some helpfull settings (not /home) and some general informatin|
|[utf8.sh](utf8.sh)|Convert text from e.g. Windows latin1 to utf8 text (e.g. in READMEs or other text (not for office documents))|
|[SchredderHDD.sh](SchredderHDD.sh)|Delete a mechanical Hard Disk (HDD) reliably to ensure before forward it to the recycling, that no old data are there| |[SchredderHDD.sh](SchredderHDD.sh)|Delete a mechanical Hard Disk (HDD) reliably to ensure before forward it to the recycling, that no old data are there|
|[utf8.sh](utf8.sh)|Convert text from e.g. Windows latin1 to utf8 text (e.g. in READMEs or other text (not for office documents))|
|[wmf2svg.sh](wmf2svg.sh)|Example script converts WMF files in SVG to share it easily on the internet| |[wmf2svg.sh](wmf2svg.sh)|Example script converts WMF files in SVG to share it easily on the internet|
|[SavePC.sh](SavePC.sh)|Save some helpfull settings (not /home) and some general informatins| |[write-exif-comment.sh](write-exif-comment.sh)|Write JPEG EXIF comment in all *.jpg files|
|[CheckKernel.sh](CheckKernel.sh)|Show some intersting Kernel informations (supports -d for debug und -v for verbose)|