ajout cmd

This commit is contained in:
Tenzing Kandang 2026-01-08 15:51:23 +01:00
parent 8ab879bc8f
commit 7b787b9653
2 changed files with 169 additions and 2 deletions

View File

@ -23,6 +23,9 @@ echo " + Welcome to Grabber +"
echo " ++++++++++++++++++++++++++++++++++"
echo " "
echo "Tout les fichiers crées se trouveront dans le dossier /opt/grabber ;)"
echo " "
#Array File
declare -a DEVICES
mapfile -t DEVICES < <(lsblk -dn -o NAME |grep -v loop)
@ -35,11 +38,33 @@ FILES=(
"ssh_config.file" "/etc/ssh/ssh_config"
)
declare -A COMMANDES
COMMANDES=(
"lspci.cmd" "lspci -nn"
"lsusb.cmd" "lsusb"
"apt.cmd" "apt list --installed"
"systemd-analyze.cmd" "systemd-analyze"
"systemd-blame.cmd" "systemd-analyze blame | head -n 10"
"lscpu.cmd" "lscpu"
"inxi.cmd" "inxi"
"lsmem.cmd" "lsmem"
)
treat_cmd() {
echo "Création fichier: $@"
$2 |grep -v '^#' |grep -v '^$' >$DIR/$1
}
treat_file() {
echo "Copie de fichier: $@"
cat $2 |grep -v '^#' | grep -v '^$' >$DIR/$1
cat $2 |grep -v '^#' |grep -v '^$' >$DIR/$1
}
for cmd in ${!COMMANDES[@]}; do
treat_cmd $cmd ${COMMANDES[$cmd]}
done
for file in ${!FILES[@]}; do
treat_file $file ${FILES[$file]}
done
@ -63,6 +88,8 @@ for disk in ${!PARTITIONS_BY_DISK[@]}; do
echo "PARTS_$disk=$(printf '%s ' ${PARTITIONS_BY_DISK[$disk]})" >>$SUM
done
hardware() {
echo " "
echo "[HARDWARE]"
@ -97,4 +124,5 @@ software() {
hardware
software
echo " "
echo "Fichier summary.txt a été crée avec les infos hardware et software du système :)"
echo "Fichier summary.txt a été crée avec les infos hardware et software du système"
echo "À bientôt ;)"

139
grabber.sh.save Executable file
View File

@ -0,0 +1,139 @@
#!/bin/bash
DIR=/opt/grabber
SUCCESS_LOG=/var/log/grabber/grabber-success.log
ERROR_LOG=/var/log/grabber/grabber-error.log
SUM="$DIR/summary.txt"
# Affichage du texte de démarrage
tee $SUCCESS_LOG $ERROR_LOG <<EOF1
+++++++++++++++++++++++++++++++++
Démarrage du script Grabber
+++++++++++++++++++++++++++++++
==============================
Récupération des informations sur les paquets
==============================
EOF1
# Fichier /etc/apt/sources.list
tee -a $SUCCESS_LOG $ERROR_LOG <<EOF2
-----------------------------------
Copie du fichier de configuration /etc/apt/sources.list
----------------------------------
EOF2
cat /etc/apt/sources.list 2> >(tee -a $ERROR_LOG) >$DIR/sources-list.file
# Commande apt list --installed
tee -a $SUCCESS_LOG $ERROR_LOG <<EOF3
-------------------------------------
Récupération de la liste des paquets installés
-------------------------------------
EOF3
apt list --installed 2> >(tee -a $ERROR_LOG) >$DIR/apt-installed.cmd \
&& echo "[OK]: Fichier apt-installed.cmd généré" |tee -a $SUCCESS_LOG \
|| echo "[ECHEC]: Erreur à la génération de apt-installed.cmd" |tee -a $ERROR_LOG
# Commande array
tee -a $SUCCESS_LOG $ERROR_LOG <<EOF4
-------------------------------------
Commandes arrays
-------------------------------------
EOF4
declare -a DEVICES
mapfile -t DEVICES < <(lsblk -dn -o NAME |grep -v loop)
declare -A FILES
FILES=(
"sources_list.file" "/etc/apt/sources.list*"
"passwd.file" "/etc/passwd"
"group.file" "/etc/group"
"ssh_config.file" "/etc/ssh/ssh_config"
)
treat_file() {
echo "Les arguments: $@"
cat $2 |grep -v '^#' | grep -v '^$' >>$DIR/$1
}
treat_cmd() {
treat_file sources_list.file /etc/apt/sources.list
for file in ${!FILES[@]}; do
treat_file $file ${FILES[$file]}
done
#cat /etc/ssh/ssh_config > $DIR/ssh_config.file
#cat /etc/passwd > $DIR/passwd.file
#cat /etc/group > $DIR/group.file
#lspci -nn > $DIR/lspci.cmd
#lsusb > $DIR/lsusb.cmd
#apt list --installed > $DIR/apt.cmd
#systemd-analyze > $DIR/systemd-analyze.cmd
#systemd-analyze blame | head -n 10 > $DIR/systemd-blame.cmd
#lscpu > $DIR/lscpu.cmd
#lshw-gtk > $DIR/lshw-gtk.cmd
#inxi > $DIR/inxi.cmd
#lsmem > $DIR/lsmem.cmd
hardware() {
declare -A PARTITIONS_BY_DISK
for disk in ${DEVICES[@]}; do
disk_path=$(printf '/dev/%s' "$disk")
disk_parts=$(lsblk -nr -o PKNAME,PATH $disk_path |grep -vE "^ " |cut -d \ -f2)
PARTITIONS_BY_DISK[$disk]=${disk_parts[@]}
done
echo "Combien de disques sur l'ordinateur ? ${#DEVICES[@]}"
echo "keys: ${!PARTITIONS_BY_DISK[@]}"
echo "values: ${PARTITIONS_BY_DISK[@]}"
echo DEVICES=${DEVICES[@]} >$SUM
for disk in ${!PARTITIONS_BY_DISK[@]}; do
echo "PARTS_$disk=$(printf '%s ' ${PARTITIONS_BY_DISK[$disk]})" >>$SUM
done
echo "[HARDWARE]" >>$SUM
echo "CPU=$(lscpu -eMODELNAME |tail -n1)" >>$SUM
echo "CPU_ID=$(sudo dmidecode -t processor |grep ID |cut -d: -f2)" >>$SUM
RAM_SIZE=$(lsmem |grep "Mémoire partagée" |cut -d: -f2 |sed 's/\ //g')
RAM_GEN=$(sudo dmidecode -t memory |grep Type: |grep -v Unknown |tail -n1 |cut -d: -f2 |sed 's/\ //')
echo "RAM=$RAM_SIZE $RAM_GEN" >>$SUM
echo "RAM_SIZE=$RAM_SIZE" >>$SUM
echo "RAM_GEN=$RAM_GEN" >>$SUM
sizes=$(lsblk -dnb |grep -v loop |grep -v boot |tr -s " " |cut -d \ -f4) >>$SUM
STOCKAGE_TOTAL=0
for SIZE in ${sizes[@]};do
STOCKAGE_TOTAL+=$SIZE
done
STOCKAGE_TOTAL=$(numfmt --to iec $STOCKAGE_TOTAL)
echo "STOCKAGE_TOTAL=$STOCKAGE_TOTAL" >>$SUM
}
hardware
software() {
echo " " >>$SUM
echo "[SOFTWARE]" >>$SUM
echo "OS=$(lsb_release -a |grep Description |cut -f2)" >>$SUM
echo "ARCH=$(uname -m)" >>$SUM
echo "DESKTOP=$XDG_CURRENT_DESKTOP" >>$SUM
echo "WM=$XDG_SESSION_TYPE" >>$SUM
echo "KERNEL=$(uname -r)" >>$SUM
}
software
structure-reseaux.txt
IP 163.173.88.157/22 : 163:10100011, 173: 10101101, 88: 01011000, 157: 100111101