Bland annat har logiken kring att kontollera processorns mikrokod förbättrats.
Poängen med "chksys" är att den kontrollerar hur systemet är uppdaterat och hur mycket av uppgraderingarna som faktiskt är i aktuell drift. Vissa uppgraderingar påverkar i stort sett inte systemet, eftersom de bara tas i drift när de används. Andra som typ kärnan och mikrokoden, plus en massa annat är i drift hela tiden och kräver en omstart (reboot) för att kunna komma in.
Själv kör jag "chksys" i stort sett efter varje uppgradering och iallafall minst ett par gånger i månaden...
(om escape-sekvenserna funkar dåligt (som det ser ut som), så säg till så kan jag maila den istället...)
- Kod: Markera allt
#! /bin/bash
#
NORMAL="[0m"
RED="[31m"
RRED="[1m[31m"
###
function oldpgm {
echo -"Example of processes running old versions:"
PROCESSES=$(checkrestart --nolsof 2>> /dev/null | grep : | sed 's/://' | sort)
let LOOP=1
IFS=$'\n'
for PROCESS in $PROCESSES; do
CNT=$(echo "$PROCESS" | wc -w)
if [[ $CNT == 1 ]]; then
echo " $PROCESS"
let LOOP+=1
else
#echo $CNT" - "$PROCESS
:
fi
done
}
function krnl {
NEW_KRNL=false
NAME=$(uname -s)
MACHINE=$(uname -m)
RUNNING_KRNL=$(uname -r)
if [[ -e /boot/vmlinuz ]]; then
NEWEST_KRNL=$(ls -l /boot/vmlinuz | awk '{ print $11 }' | sed 's/vmlinuz-//g')
else
NEWEST_KRNL=$(ls -tr /boot | grep vmlinuz | grep "-" | awk -F - '{ $1=""; print $0 }' | sed 's/^ //g' | sed 's/ /-/g' | tail -1)
if [[ -z $NEWEST_KRNL ]]; then
NEWEST_KRNL=""
fi
fi
#echo
echo "Running kernel is: $(uname -rms)"
if [[ ! -z $NEWEST_KRNL && $RUNNING_KRNL != $NEWEST_KRNL ]]; then
NEW_KRNL=true
echo -e "\033[1m\033[31m=>A newer kernel exists, consider rebooting !!!!!\033[0m"
echo "Newer kernel is: $NAME $NEWEST_KRNL $MACHINE"
elif [[ -z $NEWEST_KRNL ]]; then
echo "-Cannot check if a newer kernel exists..."
else
echo "-Ok"
fi
echo
}
function chkProc {
RETURN=0
NPROC=$(ps -ef | tail -n +2 | wc -l)
NPROCT=$(ps -efT | tail -n +2 | wc -l)
MAX_PROC=$(cat /proc/sys/kernel/pid_max)
if [[ -z $1 || $1 == "INIT" ]]; then
MAX_PROC=$(cat /proc/sys/kernel/pid_max)
MAX_UPROC=$(ulimit -u)
fi
let Z_count=0
PIDS=$(ls -d /proc/[0-9]* 2> /dev/null | awk -F/ '{ print $3 }' 2>> /dev/null)
for PID in $PIDS; do
PSTATE=$(grep State: /proc/$PID/status 2>> /dev/null| awk '{ print $2 }')
if [[ ! -z $PSTATE ]]; then
if [[ $PSTATE == "X" ]]; then
let X_count+=1
RETURN=1
elif [[ $PSTATE == "Z" ]]; then
let Z_count+=1
RETURN=1
fi
fi
done
echo "Number of processes: $NPROC"
echo "Number of processes+threads: $NPROCT"
echo "Max process limit: $MAX_PROC"
if [[ $X_count -ne 0 ]]; then
echo "-Dead processes: $X_count"
fi
if [[ $Z_count -ne 0 ]]; then
echo "-Zombie processes: $Z_count"
fi
if [[ $X_count -ne 0 || $Z_count -ne 0 ]]; then
#echo "*** Consider REBOOT ***"
echo -e "\033[1m\033[31m*** Consider rebooting ***\033[0m"
fi
return $RETURN
}
if [[ -z $EUID ]]; then
EFFUID=$(ps --no-headers -o euid --pid $$ | xargs)
else
EFFUID=$EUID
fi
clear -x
echo
echo "=============================================================================="
echo "-Up in $(uptime -p)"
echo
echo "=============================================================================="
echo '-Checking "/var/run/reboot-recuired"'
if [[ -r /var/run/reboot-required ]]; then
echo -en "\033[1m\033[31m"
REBOOT_REQ=false
REB=$(cat /var/run/reboot-required | wc -l)
if [[ $REB -gt 0 ]]; then
REBOOT_REQ=true
cat /var/run/reboot-required
else
cat /var/run/reboot-required
if [[ -r /var/run/reboot-required.pkgs ]]; then
echo "-Packages that need reboot:"
cat /var/run/reboot-required.pkgs | sort -u
else
echo "-No info about pkgs"
fi
fi
echo -en "\033[0m"
else
echo "-Ok"
fi
echo
echo "=============================================================================="
echo "-Checking kernel"
krnl
echo "=============================================================================="
echo "-Checking processes"
chkProc
echo
CHKSYS=true
DIST=$(source /etc/os-release; echo $ID | awk -F \- '{ print $1 }')
if [[ $DIST == "ubuntu" || $DIST == "linuxmint" || $DIST == "debian" ]]; then
echo "=============================================================================="
echo '-Running "needrestart"'
if [[ ! -z $(which needrestart 2> /dev/null) ]]; then
#echo
#echo "-Note that thus number may differ from the whole systems outdated processes..."
if [[ $NEW_KRNL == false && $REBOOT_REQ == false ]]; then
echo
needrestart -r l
PCNT=$(needrestart 2> /dev/null | tail -n +2 | tr -d -c '[:digit:] ' | xargs | wc -w)
echo "Outdated processes: $PCNT"
#needrestart -r l | grep "Your outdated processes"
if [[ $EFFUID != "0" ]]; then
if [[ $1 == "-f" ]]; then
PROCESSES=$(needrestart 2> /dev/null | tail -n +2 | tr -d -c '[:digit:] ' | xargs)
if [[ ! -z $PROCESSES ]]; then
echo "-Own processes that need restart:"
echo "-Info about outdated processes:"
echo "PROCESSES: $PROCESSES"
ps -fp $PROCESSES
:
fi
fi
echo
echo "-Note that this number may differ from the whole systems outdated processes..."
fi
elif [[ $NEW_KRNL == true ]]; then
echo -e "\033[1m\033[31m*** Newer kernel exists - can not run needrestart from script ***\033[0m"
echo -e "\033[1m\033[31m (it will hang due to info about that there is a newer kernel)\033[0m"
elif [[ $REBOOT_REQ == true ]]; then
echo -e "\033[1m\033[31m*** Reboot required - can not run needrestart from script ***\033[0m"
echo -e "\033[1m\033[31m (it will hang due to info about reboot)\033[0m"
fi
else
echo 'needrestart is not installed - use "sudo apt install needrestart" to install it..."'
fi
#echo
#echo "-Note that this number shows outdated processes for $RRED$USER$NORMAL, for other users it may be different..."
echo
echo "=============================================================================="
if [[ $EFFUID == "0" ]]; then
echo '-Running "checkrestart"'
#echo '-Note that most messages from "lsof" can be ignored...'
if [[ ! -z $(which checkrestart 2> /dev/null) ]]; then
echo
# OUT=$(checkrestart -t 2>> /dev/null)
# printf "Terse: %s\n" "$OUT"
ALL=$(checkrestart 2> /dev/null | grep ^Found | sed 's/Found 0 processes/No processes found/g' | sed 's/^Found //g')
# printf "All: %s\n" "$ALL"
printf " %s\n" "$ALL"
if [[ $ALL == "No processes found using old versions of upgraded files" ]]; then
NUM=0
else
NUM=1
fi
if [[ $NUM == 1 ]]; then
echo " (each name may represent more than one process...)"
echo
checkrestart 2> /dev/null | grep -v "restart" | grep -v systemd | grep -v initd | grep : | sed 's/://g' | sort
echo
else
echo
fi
else
echo 'debian-goodies is not installed - use "sudo apt install debian-goodies" to install it...'
echo
fi
else
echo '-Can not run "checkrestart", as we are not root...'
echo
fi
elif [[ $DIST == "opensuse" || $DIST == "sles" || $DIST == "sled" || $DIST == "sle" ]]; then
echo "=============================================================================="
if [[ -z $(which needs-restarting 2> /dev/null) ]]; then
echo '-Running "zypper ps"'
zypper ps
else
#echo 'yum-utils is not installed - use "sudo zypper install yum-utils" to install it...'
echo '-Running "needs-restarting"'
needs-restarting
fi
echo
elif [[ $DIST == "fedora" || $DIST == "centos" || $DIST == "redhat" || $DIST == "rhel" ]]; then
echo "=============================================================================="
if [[ ! -z $(which needs-restarting 2> /dev/null) ]]; then
echo '-Running "dnf needs-restarting -r"'
dnf needs-restarting -r
echo
else
echo '-Running "needs-restarting -r"'
needs-restarting -r
echo
fi
else
echo "=============================================================================="
echo "-$DIST is not supported yet, sorry!"
echo
fi
exit
#!/bin/sh
#< An "echo" beautifier - supports colours and boldface
open_escape="[0m"
close_escape="[0m"
case $1 in
red) open_escape="[31m"
shift ;;
Bred) open_escape="[1m[31m"
shift ;;
green) open_escape="[32m"
shift ;;
Bgreen) open_escape="[1m[32m"
shift ;;
brown) open_escape="[33m"
shift ;;
Bbrown) open_escape="[1m[33m"
shift ;;
blue) open_escape="[34m"
shift ;;
Bblue) open_escape="[1m[34m"
shift ;;
lilac) open_escape="[35m"
shift ;;
Blilac) open_escape="[1m[35m"
shift ;;
lblue) open_escape="[36m"
shift ;;
Blblue) open_escape="[1m[36m"
shift ;;
white) open_escape="[1;37m"
shift ;;
Bwhite) open_escape="[1m[1;37m"
shift ;;
bold) open_escape="[1m"
shift ;;
*) shift ;;
esac
echo "${open_escape}$*${close_escape}"
###
## Commnt to turn function of when cat - [0m
###
exit 0
