scandir 1.4.0

This commit is contained in:
kyodev 2017-10-17 18:49:26 +02:00
parent 0b8ec48b99
commit 24a1cf16c0
1 changed files with 33 additions and 17 deletions

View File

@ -1,7 +1,7 @@
#!/bin/bash
version=1.3.0
date=15/10/2017
version=1.4.0
date=17/10/2017
BOLD=$(tput bold)
STD=$(tput sgr0)
@ -23,8 +23,9 @@ f__requis(){ # version spécifique
fi
}
# $1=rep à scanner [$2=profondeur max|4 défaut] [$3=profondeur encours|0 défaut] /usr/bin/strings (binutils) requis
f__scandir(){ # 15/10/2017
# $1=rep à scanner [$2=profondeur max|4 défaut] [$3=profondeur encours|0 défaut]
# affichage stdout si $fileOutput non définis, /usr/bin/strings (binutils) requis
f__scandir(){ # 17/10/2017
[ -d "$1" ] || f__error "erreur sur le répertoire à scanner"
f__requis "strings>binutils" # requis pour fonctionnement programme
local repToScan irep rc text prof prof_max tempo
@ -71,22 +72,23 @@ help(){ # 15/10/2017
exit 1
}
# fileOutput, [ $1=_end ]
fileSortie(){ # 15/10/2017
# fileOutput, [ $1=_end ] [ $2=profondeur <> de $profondeur ]
fileSortie(){ # 17/10/2017
local prof
# fin file output
if [ "$1" == "_end" ]; then
echo '``` ' >> "$fileOutput"
return 0
fi
[ "$2" ] && prof="$2" || prof="$profondeur"
# formation nom fileOutput
fileOutput=$(sed s#/#_#g <<< $1) # remplace / par _
fileOutput=$(sed 's#/#_#g' <<< $1) # remplace / par _
[ "${fileOutput: -1}" == "_" ] && fileOutput=${fileOutput::-1} # suppression dernier _ éventuel
fileOutput="$(dirname $0)/$fileOutput" #fichier de sauvegarde
# entete fileOutput
echo "$(basename $0) $version " > "$fileOutput"
echo "# scan: $1 " >> "$fileOutput"
echo "profondeur: $profondeur " >> "$fileOutput"
echo "profondeur: $prof " >> "$fileOutput"
echo "hôte: $(uname -n) " >> "$fileOutput"
echo "$(date '+%d/%m/%Y %H:%M %z')" >> "$fileOutput"
echo >> "$fileOutput"
@ -103,18 +105,32 @@ fileSortie(){ # 15/10/2017
[[ -d "$1" || "$1" == "all" ]] || help # si appel incorrect, help
[ "$2" ] && profondeur=$2 || profondeur=4 # profondeur par défaut
liste="/proc/sys/vm/ /sys/class/dmi/ /sys/class/hwmon/ /sys/class/net/
/sys/class/power_supply/ /sys/devices/system/cpu"
# syntaxe pour une profondeur spécifique autre que 4: répertoire>profSpécifiq
# * pour expansion nom de fichier/répertoire permis
# /!\ biensur, pas d'espaces dans les répertoire à scanner
liste="
/proc/acpi/ /proc/sys/vm/
/sys/class/>2 /sys/class/dmi/ /sys/class/hwmon/ /sys/class/net/>2 /sys/class/power_supply/
/sys/class/thermal/>3
/sys/devices/>2 /sys/devices/platform/coretemp.*/>2 /sys/devices/system/cpu /sys/devices/virtual/>3
/sys/class/thermal/thermal_zone0/>2 /sys/devices/virtual/thermal/thermal_zone0/>2 "
#### scandir
if [ "$1" == "all" ];then
if [ "$1" == "all" ];then # scan liste
for ifile in $liste; do
echo "scan $ifile"
fileSortie "$ifile"
f__scandir "$ifile" "$profondeur"
fileSortie "_end"
for ifilex in $(cut -d '>' -f1 <<< $ifile); do # décompose le nom si *
echo "scan: $ifilex"
if [ "$(cut -d '>' -f2 <<< $ifile | grep -c '[0-9]')" -eq 1 ]; then #2e champs numérique
fileSortie "$ifilex" "$(cut -d '>' -f2 <<< $ifile)"
f__scandir "$ifilex" "$(cut -d '>' -f2 <<< $ifile)"
else
fileSortie "$ifilex"
f__scandir "$ifilex" "$profondeur"
fi
fileSortie "_end"
done
done
else
else # scan unitaire
fileSortie "$1"
f__scandir "$1" "$profondeur"
fileSortie "_end"