getInfo 2.28.0

This commit is contained in:
kyodev 2017-11-09 11:43:42 +01:00
parent 52ad6c664b
commit fa0d125f1b
3 changed files with 83 additions and 37 deletions

View File

@ -1,7 +1,7 @@
#!/bin/bash
version=2.27.0
date="08/11/2017"
version=2.28.0
date="09/11/2017"
projet="simpledeb"
contact="IRC freenode ##sdeb ou https://framagit.org/kyodev/kyopages/issues/"
script="getInfo"
@ -337,6 +337,16 @@ f_display(){ # 08/11/2017
echo -en "$display \n" >> "$fileOutput" # flush fonction
}
# f_dspl_alert: $1 variable à afficher en alerte/info
f_dspl_alert(){ # 09/11/2017
# flush, avant fonction, de text parent
[ "$text" ] && echo -en "$text" >> "$fileOutput"
unset text
# coeur fonction
[ "${!1}" ] && text+="> ${!1} \n\n"
echo -en "$display \n" >> "$fileOutput" # flush fonction
}
# $1 fichier testé
f_dspl_file_ko(){ # 03/11/2017
echo -e "* fichier **$1** non trouvé ou absent \n" >> "$fileOutput"
@ -357,16 +367,24 @@ f_dspl_grep(){ # 07/11/2017
done
}
# $1 file à parser. tout en bash pour regex par défaut non-greedy (non gourmand) comme sed ou gawk
# traitement ligne par ligne, l'italique avec _ n'est pas géré
f_dspl_md(){ # 08/11/2017
local display display2
# $1 file à parser
# tout en bash pour regex par défaut non-greedy (non gourmand) comme sed ou gawk
# contrainte markdown:
# l'italique avec _ ou * n'est pas géré, trop d'interférences potentielles
# liste niveau2: 3 ou 4 caractères, niveau3: 6 ou 8 caractères, puce * ou -
f_dspl_md(){ # 09/11/2017
local display display2 ifs_origin
if [ ! -f "$1" ]; then
f__info "pas de rapport à afficher, vous devez lancer une analyse auparavant:" \
"$GREEN$script -l$BLUE ou afficher l'aide $GREEN$script -h"
return 0
fi
display=$(< $1)
display=${display//\`\`\`/~~~} # transforme ``` en ---, plus visibles
#DEFAUT: espaces en début de lignes bouffés
display=${display//\`\`\`/--} # transforme ``` en --, plus visibles
# traitement par lignes, ala sed, obligatoire pour les titres #
# plus simple pour les multi-patterns, sinon matches multilignes délicats à gérer en cas d'impairage
# while read ligne; do
ifs_origin="$IFS"
IFS="\n"
while read ligne; do
# # TITRE 1 red
[[ "$ligne" =~ ^(#[^#].*)$ ]] && ligne="\x1B[31m"${BASH_REMATCH[1]}"\x1B(B\x1B[m"
@ -374,23 +392,28 @@ f_dspl_md(){ # 08/11/2017
[[ "$ligne" =~ ^(#{2}[^#].*)$ ]] && ligne="\x1B[34m"${BASH_REMATCH[1]}"\x1B(B\x1B[m"
# ### TITRE 3 green
[[ "$ligne" =~ ^(#{3}[^#].*)$ ]] && ligne="\x1B[32m"${BASH_REMATCH[1]}"\x1B(B\x1B[m"
# ### TITRE 4 yellow
# #### TITRE 4 yellow
[[ "$ligne" =~ ^(#{4}[^#].*)$ ]] && ligne="\x1B[33m"${BASH_REMATCH[1]}"\x1B(B\x1B[m"
# **gras**
while [[ "$ligne" =~ (.*)\*{2}(.*)\*{2}(.*) ]]; do
ligne=${BASH_REMATCH[1]}'\x1B[1m'${BASH_REMATCH[2]}'\x1B(B\x1B[m'${BASH_REMATCH[3]}
done
# *italique*, _italique_ trop d'interférences avec sorties du rapport
while [[ "$ligne" =~ (.*)\*([^*].*)\*(.*) ]]; do
ligne=${BASH_REMATCH[1]}'\x1B[3m'${BASH_REMATCH[2]}'\x1B(B\x1B[m'${BASH_REMATCH[3]}
done
# ` backtick mis en gras
while [[ "$ligne" =~ (.*)\`([^\`].*)\`(.*) ]]; do
ligne=${BASH_REMATCH[1]}'\x1B[1m'${BASH_REMATCH[2]}'\x1B(B\x1B[m'${BASH_REMATCH[3]}
done
# puces niveau 1
ligne=${ligne/#\*[^*]/• }
ligne=${ligne/#-[^-]/• }
# puces niveau 2
[[ "$ligne" =~ ^([[:space:]]{3,4})\*(.*)$ ]] && ligne=${BASH_REMATCH[1]}'► '${BASH_REMATCH[2]}
[[ "$ligne" =~ ^([[:space:]]{3,4})-(.*)$ ]] && ligne=${BASH_REMATCH[1]}'► '${BASH_REMATCH[2]}
# puces niveau 3
[[ "$ligne" =~ ^([[:space:]]{6,8})\*(.*)$ ]] && ligne=${BASH_REMATCH[1]}'◾ '${BASH_REMATCH[2]}
[[ "$ligne" =~ ^([[:space:]]{6,8})-(.*)$ ]] && ligne=${BASH_REMATCH[1]}'◾ '${BASH_REMATCH[2]}
display2+="$ligne\n"
done <<< "$display"
IFS="$ifs_origin"
echo -e "$display2"
}
@ -737,9 +760,9 @@ SMCA ⟷ Scalable MCA
"
}
fi_disk(){ # 08/11/2017
local disk_lsblk disk_df disk_df_i fstab resume idResume idSwap alert_uuidResume text pluriel
local dd_temp dd_temp_alert dd_temp idisk tempodd
fi_disk(){ # 09/11/2017
local disk_lsblk disk_df disk_df_i fstab resume idResume idSwap dd_temp tempodd idisk text pluriel
local alert_uuidResume alert_dd_temp
disk_lsblk="$(lsblk -o NAME,FSTYPE,SIZE,LABEL,MOUNTPOINT,UUID)"
disk_df="$(df -h --output=source,target,fstype,size,used,avail,pcent --exclude=tmpfs --exclude=devtmpfs | grep -Ev 'devpts|none|proc|sys|tmpfs|udev')"
disk_df_i="$(df -i --exclude=tmpfs --exclude=devtmpfs | grep -Ev 'devpts|none|proc|sys|tmpfs|udev')"
@ -761,21 +784,21 @@ fi_disk(){ # 08/11/2017
fi
[ "$fg_nb_disk" ] || figet_disk
if [ "$(f__cmd_exist hddtemp)" ]; then
unset dd_temp dd_temp_alert
unset dd_temp alert_dd_temp
for idisk in $fg_disk_fixe; do
[ -r "/dev/$idisk" ] || continue
tempodd="$(LC_ALL=C hddtemp /dev/$idisk | cut -d ':' -f3 | sed 's/[^0-9]*//g; /not available/d')"
dd_temp+="$idisk: $tempodd °C"$'\n'
[ "$tempodd" -ge 50 ] && dd_temp_alert+="/!\ $idisk: température > 50°C) "$'\n'
[ "$tempodd" -ge 50 ] && alert_dd_temp+="/!\ $idisk: température > 50°C) "$'\n'
done
[ "$dd_temp" ] && dd_temp=${dd_temp::-1} # suppression dernier $'\n'
[ "$dd_temp_alert" ] && dd_temp_alert=${dd_temp_alert::-1} # suppression dernier $'\n'
[ "$alert_dd_temp" ] && alert_dd_temp=${alert_dd_temp::-1} # suppression dernier $'\n'
fi
###
[ "$fg_nb_disk" -gt 1 ] && pluriel="s" || unset pluriel
text="## disque$pluriel \n\n"
# espace des partitions fixes montées
text+="* $fg_disk_part_fix_tot \n\n"
text+="* $(gawk -F': ' '{print $1": **"$2"**"}' <<< $fg_disk_part_fix_tot) \n\n"
text+='``` \n'
# disques fixes et amovibles
[ "$(wc -w <<< $fg_disk_fixe)" -gt 1 ] && pluriel="s" || unset pluriel
@ -799,13 +822,13 @@ fi_disk(){ # 08/11/2017
text+='``` \n\n'
text+="**types de disque** \n\n"
text+="| sata | usb | mmc | nvme | \n"
text+="| :---: | :---: | :---: | :---: | \n"
text+="| :---: | :---: | :---: | :---: | \n"
text+="| $fg_disk_ata | $fg_disk_usb | $fg_disk_mmc | $fg_disk_nvme | \n\n"
# éventuellement hddtemp
[ "$dd_temp" ] && f_display "dd_temp" "cmd" "hddtemp /dev/sd?" "température disques"
if [ "$dd_temp_alert" ]; then
text+="$dd_temp_alert \n"
text+="$dd_temp_alert_text \n\n"
if [ "$alert_dd_temp" ]; then
text+="$alert_dd_temp \n"
text+="$alert_dd_temp_text \n\n"
fi
# df, espaces des partitions montées seules
f_display "disk_df" "cmd" \
@ -981,12 +1004,14 @@ fi_hw(){ # 03/11/2017
unset text
}
fi_journal(){ # 08/11/2017
local jctl_boot jctl_alert_k jctl_crit_k jctl_err_k jctl_warn_k jctl_warn_nok jctl_size file text nb_lignes=25
fi_journal(){ # 09/11/2017
local jctl_boot jctl_alert_k jctl_crit_k jctl_err_k jctl_warn_k jctl_warn_nok jctl_size file
local jctl_persist alert_jctl_persist text nb_lignes=25
[ "$(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 | sed -n '/^-- Logs begin.*$/p' > $file-boot ; \
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 2>/dev/null 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 ; \
@ -1002,6 +1027,12 @@ fi_journal(){ # 08/11/2017
return 0
fi
jctl_boot=$(gawk -F '--|,' '{ sub(/^ /,"",$2);print $2}' <<< $(cat $file-boot))
jctl_persist=$(grep -c 'no persistent journal' $file-persistant)
if [ "$jctl_persist" -eq 0 ]; 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\`"
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)
@ -1019,6 +1050,7 @@ fi_journal(){ # 08/11/2017
###
# kernel
text="## journalctl kernel (emergency, alert, erreur, warning ou critique) \n\n"
f_dspl_alert "alert_jctl_persist"
text+="* $jctl_boot \n\n"
f_display "jctl_alert_k" "cmd" "journalctl --no-hostname --boot 0 -k -p 1" \
"kernel emergency 0 & alerte 1, $nb_lignes premières lignes"
@ -2183,11 +2215,13 @@ figet_ip_pub(){ # 27/10/2017
# $1=mem|swap [total|notitle|nocoltitle], assigne $fg_mem ($2=debug all cols + free)
# indépendant de procps, affichage plus clair que free, mais résultats identiques
figet_mem(){ # 31/10/2017
local freeDebug MemTotal MemFree MemAvailable Buffers Cached SReclaimable Shmem MemUsed
figet_mem(){ # 09/11/2017
local freeDebug MemTotal MemFree MemAvailable Buffers Cached SReclaimable Shmem MemUsed ifs_origin
local SwapTotal SwapFree SwapCached col
[ "$2" == "debug" ] && freeDebug="$(free -hw | sed '3d')"
while IFS=':' read a b; do
ifs_origin=$IFS
IFS=':'
while read a b; do
[ "$a" == "MemTotal" ] && MemTotal="${b/kB}" #echo "$a $((${b/kB}/1024))" ! partie entière !
[ "$a" == "MemAvailable" ] && MemAvailable="${b/kB}"
[ "$a" == "MemFree" ] && MemFree="${b/kB}"
@ -2199,6 +2233,7 @@ figet_mem(){ # 31/10/2017
[ "$a" == "SwapFree" ] && SwapFree="${b/kB}"
[ "$a" == "SwapCached" ] && SwapCached="${b/kB}"
done <<< $(< /proc/meminfo)
IFS=$ifs_origin
MemUsed=$(( $MemTotal-($MemFree+$Buffers+$Cached+$SReclaimable) ))
SwapUsed=$(( $SwapTotal-$SwapFree ))
totalTotal=$(( $MemTotal+$SwapTotal ))
@ -2758,7 +2793,7 @@ for j in $options; do
case $j in
-t | --test )
prg_1 "$*"
fi_log_xorg
fi_disk
exit ;; # test
-c* | all )
[ "$j" == "-c" ] && exec $0 "menu"
@ -2772,9 +2807,7 @@ for j in $options; do
prg_2 "a"
exit ;; # exporte le rapport existant
-l )
[ -e $fileOutput ] && f_dspl_md "$fileOutput" || f__info "pas de rapport à afficher" \
"vous devez lancer une analyse auparavant: $GREEN$script -l" \
"ou afficher l'aide $GREEN$script -h"
f_dspl_md "$fileOutput"
exit ;; # afficher le rapport existant
-p )
fipaste

View File

@ -3,9 +3,16 @@
* f__wcv, f_display_grep, f__wget_test, fscript_get_version, fscript_update
## 2.28.0 09/11/2017
* nouveaux: f_dspl_alert, début homogénéisation alertes/infos
* révision: figet_mem, protection IFS
* révision: fi_journal, meilleur vitesse quand logs nombreux, alerte journaux non persistants
* révision: f_dspl_md, espaces en début de ligne préservés, listes
## 2.27.0 08/11/2017
* nouveau: moteur d'affiche console (md2console)
* nouveau: f_dspl_md, moteur d'affiche console (md2console)
* renommage fonction display, révision affichage f_display
* révision: fi_system_analyse, fi_mem: affichage

View File

@ -23,6 +23,12 @@ caractères **jhg ege ejg eesj ** gras
caractères *AZVVE ddd G EGRR* italiques
caractères AZVVE ddd G EGRR italiques (ligne de comparaison)
* ligne 1
* ligne 1.1
* ligne 1.1.1
- ligne 2
- ligne 2.1
- ligne 2.1.1
```
code
ligne avec * ` ** # ## ### ####