getInfo 2.34.0

This commit is contained in:
kyodev 2017-11-14 16:59:44 +01:00
parent b5b969efe8
commit e04a816460
2 changed files with 75 additions and 41 deletions

View File

@ -359,9 +359,9 @@ f_dspl_alert(){ # 10/11/2017
[ "${!1}" ] || return 0 # test si contenu dans $1
[[ "$2" =~ "info" ]] && type="info"
[[ "$2" =~ alert ]] && type="alert"
[ "$type" == "alert" ] && display="\n> ❗ ${!1} \n"
[ "$type" == "info" ] && display="\n ☛ ${!1} \n"
echo -en "$display \n" >> "$fileOutput" # flush fonction
[ "$type" == "alert" ] && display="\n> ❗ ${!1} \n"
[ "$type" == "info" ] && display="\n ☛ ${!1} \n"
echo -en "\n$display \n" >> "$fileOutput" # flush fonction
}
# conversion markdown pour affichage en console, $1 file à parser
@ -789,14 +789,14 @@ SMCA ⟷ Scalable MCA
"
}
fi_disk(){ # 13/11/2017
fi_disk(){ # 14/11/2017
local dd_temp="" disk_df disk_df_i disk_lsblk fstab resume idResume idSwap idisk text pluriel
local alert_dd_temp alert_file_resume alert_uuidResume
# éventuellement hddtemp
if [ "$(f__cmd_exist hddtemp)" ]; then
for idisk in $fg_disk_fixe; do
[ -r "/dev/$idisk" ] || continue
dd_temp="$(LC_ALL=C hddtemp /dev/$idisk | cut -d ':' -f3 | sed 's/[^0-9]*//g; /not available/d')"
dd_temp=$( LC_ALL=C hddtemp -n /dev/$idisk | sed 's/[^0-9]*//g; /not available/d' )
if [ "$dd_temp" -ge 50 ]; then
alert_dd_temp+="$idisk: température > 50°C"$'\n'
fi
@ -1047,19 +1047,19 @@ fi_hw(){ # 10/11/2017
unset text
}
fi_journal(){ # 10/11/2017
local jctl_boot jctl_alert_k jctl_crit_k jctl_err_k jctl_warn_k jctl_warn_nok jctl_size file
fi_journal(){ # 14/11/2017
local jctl_boot jctl_alert_k jctl_crit_k jctl_err_k jctl_warn_k jctl_warn_nok jctl_last jctl_size file
local text nb_lignes=25
local alert_jctl_persist
[ "$(f__cmd_exist journalctl)" ] || fi_dmesg # pas systemd, appel dmesg
file="/tmp/$$-$RANDOM-journalctl"
[ "$EUID" -eq 0 ] || echo
f__sudo "LC_ALL=C journalctl --no-hostname --boot 0 | head | sed -n '/^-- Logs begin.*$/p' > $file-boot ; \
LC_ALL=C journalctl --no-hostname --boot -1 &>$file-persistant ; \
LC_ALL=C journalctl --no-hostname --boot 0 -k -p 1 > $file-alert ; \
LC_ALL=C journalctl --no-hostname --boot 0 -k -p 2..2 > $file-crit ; \
LC_ALL=C journalctl --no-hostname --boot 0 -p 3..3 > $file-err ; \
LC_ALL=C journalctl --no-hostname --boot 0 -p 4..4 > $file-warn ; \
f__sudo " LC_ALL=C journalctl --no-hostname --boot -1 &>$file-persistant ; \
LC_ALL=C journalctl --no-pager --no-hostname --boot 0 -k -p 1 > $file-alert ; \
LC_ALL=C journalctl --no-pager --no-hostname --boot 0 -k -p 2..2 > $file-crit ; \
LC_ALL=C journalctl --no-pager --no-hostname --boot 0 -p 3..3 > $file-err ; \
LC_ALL=C journalctl --no-pager --no-hostname --boot 0 -p 4..4 > $file-warn ; \
LC_ALL=C journalctl --no-pager --no-hostname --boot 0 -p 4 -n$nb_lignes > $file-last ; \
LC_ALL=C journalctl --disk-usage > $file-size ; \
chown $user_: $file-*"
if [ "$?" != "0" ]; then
@ -1070,32 +1070,47 @@ fi_journal(){ # 10/11/2017
echo -e "$text" >> "$fileOutput"
return 0
fi
jctl_boot=$(gawk -F '--|,' '{ sub(/^ /,"",$2);print $2}' <<< $(cat $file-boot))
# début des logs, extraction à partir de file-last (toujours lignes) pour début des logs
jctl_boot=$(gawk -F '--|,' 'FNR==1 {sub(/^ /,"",$2);sub(/Logs begin at/,"Début des logs:",$2);print $2}' $file-last)
jctl_boot=$( date -d "${jctl_boot##*logs: }" ) # passage en langue locale
# test persistance
if grep -iq 'no persistent journal' "$file-persistant"; then
alert_jctl_persist="les journaux ne sont pas persistants, revoir les logs du précédent boot "
alert_jctl_persist+="n'est donc pas possible pour investiguation avec, par exemple: \n"
alert_jctl_persist+=" \`journalctl --no-hostname --boot -1\`"
alert_jctl_persist+=" journalctl --no-hostname --boot -1"
fi
jctl_alert_k=$(sed '/kernel:/!d' $file-alert | sed -n 1,"$nb_lignes"p) # emergency & alert
jctl_crit_k=$(sed '/kernel:/!d' $file-crit | sed -n 1,"$nb_lignes"p)
jctl_err_k=$(sed '/kernel:/!d' $file-err | sed -n 1,"$nb_lignes"p)
jctl_warn_k=$(sed '/kernel:/!d' $file-warn | sed -n 1,"$nb_lignes"p)
# journaux kernel
jctl_alert_k=$( sed '/kernel:/!d' $file-alert | sed -n 1,"$nb_lignes"p ) # emergency & alert
jctl_crit_k=$( sed '/kernel:/!d' $file-crit | sed -n 1,"$nb_lignes"p )
jctl_err_k=$( sed '/kernel:/!d' $file-err | sed -n 1,"$nb_lignes"p ) # uniquement lignes avec kernel, élimine no entries et logs begin
jctl_warn_k=$( sed '/kernel:/!d' $file-warn | sed -n 1,"$nb_lignes"p )
# taille des journaux
jctl_size=$(grep -Eo '[0-9]*\.[0-9]*[[:alpha:]]{1,2}' $file-size | sed 's/M/ Mo/' )
[ "$jctl_alert_k" ] || jctl_alert_k=" <vide>"
[ "$jctl_crit_k" ] || jctl_crit_k=" <vide>"
[ "$jctl_err_k" ] || jctl_err_k=" <vide>"
[ "$jctl_warn_k" ] || jctl_warn_k=" <vide>"
jctl_alert_nok=$(sed '/-- Logs begin/d;/kernel:/d; s/-- No entries --/ <vide>/' $file-alert | sed -n 1,"$nb_lignes"p)
jctl_crit_nok=$(sed '/-- Logs begin/d;/kernel:/d; s/-- No entries --/ <vide>/' $file-crit | sed -n 1,"$nb_lignes"p)
jctl_err_nok=$(sed '/-- Logs begin/d;/kernel:/d; s/-- No entries --/ <vide>/' $file-err | sed -n 1,"$nb_lignes"p)
jctl_warn_nok=$(sed '/-- Logs begin/d;/kernel:/d; s/-- No entries --/ <vide>/' $file-warn | sed -n 1,"$nb_lignes"p)
# signalement fichier vides ou suppression origine kernel (gain de place)
[ "$jctl_alert_k" ] && jctl_alert_k=${jctl_alert_k//kernel:/:} || jctl_alert_k=" ‣ vide"
[ "$jctl_crit_k" ] && jctl_crit_k=${jctl_crit_k//kernel:/:} || jctl_crit_k=" ‣ vide"
[ "$jctl_err_k" ] && jctl_err_k=${jctl_err_k//kernel:/:} || jctl_err_k=" ‣ vide"
[ "$jctl_warn_k" ] && jctl_warn_k=${jctl_warn_k//kernel:/:} || jctl_warn_k=" ‣ vide"
# journaux hors kernel
jctl_alert_nok=$(sed '/-- Logs begin/d;/kernel:/d; s/-- No entries --/ ‣ vide/' $file-alert | \
sed -n 1,"$nb_lignes"p)
jctl_crit_nok=$(sed '/-- Logs begin/d;/kernel:/d; s/-- No entries --/ ‣ vide/' $file-crit | \
sed -n 1,"$nb_lignes"p)
jctl_err_nok=$(sed '/-- Logs begin/d;/kernel:/d; s/-- No entries --/ ‣ vide/' $file-err | \
sed -n 1,"$nb_lignes"p)
jctl_warn_nok=$(sed '/-- Logs begin/d;/kernel:/d; s/-- No entries --/ ‣ vide/;s/<warn>//
' $file-warn | sed -n 1,"$nb_lignes"p)
# dernières lignes, toute provenance
jctl_last=$(sed '/-- Logs begin/d; s/-- No entries --/ ‣ vide/;s/<warn>//' $file-last)
# suppression fichier de transfert
rm "$file-"*
###
# kernel
text="## journalctl kernel (emergency, alert, erreur, warning ou critique) \n\n"
f_dspl_alert "alert_jctl_persist" "info"
text+="* $jctl_boot \n\n"
f_display "jctl_alert_k" "cmd" "journalctl --no-hostname --boot 0 -k -p 1" \
f_dspl_alert "alert_jctl_persist" "info"
# journaux kernel
f_display "jctl_alert_k" "cmd" "journalctl --no-hostname --boot 0 -k -p1" \
"kernel emergency 0 & alerte 1, $nb_lignes premières lignes"
f_display "jctl_crit_k" "cmd" "journalctl --no-hostname --boot 0 -k -p 2..2" \
"kernel critique, $nb_lignes premières lignes"
@ -1103,7 +1118,7 @@ fi_journal(){ # 10/11/2017
"kernel erreur, $nb_lignes premières lignes)"
f_display "jctl_warn_k" "cmd" "journalctl --no-hostname --boot 0 -k -p 4..4" \
"kernel warning, $nb_lignes premières lignes"
# non kernel
# journaux hors kernel
text+="## journalctl hors kernel (emergency, alert, erreur, warning ou critique) \n\n"
text+="* $jctl_boot \n\n"
f_display "jctl_alert_nok" "cmd" "journalctl --no-hostname --boot 0 -p 1 | grep -v kernel" \
@ -1114,8 +1129,12 @@ fi_journal(){ # 10/11/2017
"hors kernel, erreur, $nb_lignes premières lignes"
f_display "jctl_warn_nok" "cmd" "journalctl --no-hostname --boot 0 -p 4..4 | grep -v kernel" \
"hors kernel, warning, $nb_lignes premières lignes"
#informations
text+="* les $nb_lignes premières lignes commencent à la date du dernier boot \n\n"
f_display "jctl_size" "cmd" "journalctl --disk-usage " "taille des journaux"
# dernières lignes
f_display "jctl_last" "cmd" "journalctl --no-pager --no-hostname --boot 0 -p 4 -n25" \
"toutes provenance, emergency-warning, $nb_lignes lignes les plus récentes"
printf "$text\n" >> "$fileOutput"
unset text
}
@ -1389,10 +1408,10 @@ fi_pkg__ctl(){ #v1 13/11/2017
fi
}
fi_pkg_apt(){ #v2 13/11/2017
local sources dateMaj nb_packages upgrade upgrade_qte remove remove_qte non_ii_qte text pluriel
fi_pkg_apt(){ #v2 14/11/2017
local sources dateMaj nb_packages upgrade upgrade_qte remove remove_qte non_ii_qte deborphan text pluriel
local alert_non_list ifile alert_httpredir alert_upgrade alert_full_upgrade alert_upgrade_titre
local alert_remove alert_remove_titre alert_non_ii alert_non_ii_titre alert_non_ii_info
local alert_remove alert_remove_titre alert_non_ii alert_non_ii_comment alert_non_ii_info alert_deborphan
# sources & divers
sources=$(f_grep_file "/etc/apt/sources.list /etc/apt/sources.list.d/*.list" 8)
if [ $( ls -1 /etc/apt/sources.list.d/ | grep -cEv '\.list$' ) -gt 0 ]; then
@ -1406,7 +1425,7 @@ fi_pkg_apt(){ #v2 13/11/2017
alert_httpredir="ces urls sont obsolètes, préférer http://deb.debian.org/ ou un miroir local: \n\n"
alert_httpredir+="$(grep 'httpredir' <<< "$sources")"
fi
printf ""
printf ""
# upgradable
upgrade=$(LC_ALL=C apt-get upgrade --simulate | grep -E 'Inst | newly installed' )
upgrade=$(sort <<< $upgrade)
@ -1423,7 +1442,7 @@ fi_pkg_apt(){ #v2 13/11/2017
[ "${upgrade_qte[1]}" -gt 1 ] && pluriel="s" || unset pluriel
alert_full_upgrade="${upgrade_qte[1]} paquet"$pluriel" à mettre à jour avec \`apt full-upgrade\` (maj profonde)"
fi
printf ""
printf ""
# autoremove
remove=$(LC_ALL=C apt-get autoremove --simulate | grep -E 'Remv | newly installed' )
remove=$(sort <<< $remove)
@ -1437,15 +1456,15 @@ fi_pkg_apt(){ #v2 13/11/2017
alert_remove+="au besoin, les marquer comme installés manuellement avec apt-mark \n"
alert_remove+="ou les installer manuellement avec apt install <paquet>"
fi
printf ""
printf ""
# paquet non ^ii
alert_non_ii="$(LC_ALL=C dpkg -l | gawk 'FNR>5 && ! /^i/ {
printf "%-3s %-20s %-12s",$1,$2,$3; $1=$2=$3=$4=""; printf "%s \n",$0}')"
non_ii_qte=$( f__wcv -l "$alert_non_ii" )
if [ "$non_ii_qte" -gt 0 ]; then
[ "$non_ii_qte" -gt 1 ] && pluriel="s" || unset pluriel
alert_non_ii_titre="\n\n$non_ii_qte paquet"$pluriel" dans un état non installé"
[[ ${alert_non_ii,,} =~ ^. ]] && alert_non_ii+=" ‣ État souhaité "$'\n'
alert_non_ii_comment="$non_ii_qte paquet"$pluriel" dans un état non installé"
[[ ${alert_non_ii,,} =~ ^. ]] && alert_non_ii+="\n\n ‣ État souhaité "$'\n'
[[ ${alert_non_ii,,} =~ ^h ]] && alert_non_ii+=" h.. hold (à garder) "$'\n'
[[ ${alert_non_ii,,} =~ ^i ]] && alert_non_ii+=" i.. install (à installer) "$'\n'
[[ ${alert_non_ii,,} =~ ^p ]] && alert_non_ii+=" p.. purge (à purger) "$'\n'
@ -1465,7 +1484,16 @@ fi_pkg_apt(){ #v2 13/11/2017
if grep -iq '^rc ' <<< "$alert_non_ii"; then
alert_non_ii_info="les paquets dans un état 'rc' (fichiers de configuration restants) "
alert_non_ii_info+="peuvent être purgés avec : \n"
alert_non_ii_info+="\`dpkg --purge \$(dpkg -l | awk '/^rc/{print \$2}')\`"
alert_non_ii_info+="dpkg --purge \$(dpkg -l | awk '/^rc/{print \$2}')"
fi
fi
if [ $( f__cmd_exist deborphan ) ]; then
if [ $( deborphan ) ]; then
deborphan=$( deborphan -P )
[ $( f__wcv "-l" "$deborphan" ) -gt 1 ] && pluriel="s" || unset pluriel
alert_deborphan="bibliothèque"$pluriel" orpheline"$pluriel", suppression possible: \n"
alert_deborphan+=" apt remove \$(deborphan) \n"
alert_deborphan+="recherche légère, mais vérifier avant de valider la suppression"
fi
fi
###
@ -1478,8 +1506,10 @@ fi_pkg_apt(){ #v2 13/11/2017
f_display "alert_upgrade" "cmd" "apt list --upgradable" "$alert_upgrade_titre"
[ "$alert_full_upgrade" ] && text+="* $alert_full_upgrade \n\n"
f_display "alert_remove" "cmd" "apt autoremove --simulate" "$alert_remove_titre"
f_display "alert_non_ii" "cmd" "dpkg -l | gawk '/^rc/{print \$2}" "$alert_non_ii_titre"
f_display "alert_non_ii" "cmd" "dpkg -l | gawk '/^rc/{print \$2}" "$alert_non_ii_comment"
f_dspl_alert "alert_non_ii_info" "info"
f_display "deborphan" "cmd" "deborphan -P" "bibliothèques orphelines"
f_dspl_alert "alert_deborphan" "info"
printf "$text\n" >> "$fileOutput"
unset text
}

View File

@ -4,8 +4,12 @@
* ! f__requis, fscript_install, f__scandir
## 2.33.1 14/11/2017
## 2.34.0 14/11/2017
* nouveau, deborphan dans fi_pkg_apt
* révision: fi_journaux, derniers logs, affichage
* fix: fi_disk, température via hddtemp
* révision: fi_graph
## 2.33.0 13/11/2017