logo Debian Debian Debian-France Debian-Facile Debian-fr.org Forum-Debian.fr Debian ? Communautés logo inclusivité

Debian-facile

Bienvenue sur Debian-Facile, site d'aide pour les nouveaux utilisateurs de Debian.

Vous n'êtes pas identifié(e).


L'icône rouge permet de télécharger chaque page du wiki visitée au format PDF et la grise au format ODT → ODT PDF Export

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
Prochaine révision Les deux révisions suivantes
utilisateurs:tawal:scripts:apt-history-research [10/03/2023 03:47]
Tawal [Apt History Research]
utilisateurs:tawal:scripts:apt-history-research [14/05/2023 13:22]
Tawal [Outil de recherche dans l'historique d'apt]
Ligne 1: Ligne 1:
-====== ​Apt History Research ​======+====== ​Outil de recherche dans l'​historique d'​apt ​====== 
 +<​note>​\\ 
 +Mise à jour le : 12/​05/​2023</​note>​\\
  
-  * Outil de recherche dans l'​historique d'apt. 
  
-  * Nécessite ​//gawk// apt install gawk+  * Outil de recherche dans l'​historique d'​apt. 
 +       * Recherche par motif de nom de paquet 
 +       * Recherche par la date 
 +       * Recherche par la commande d'​appel d'//apt// 
 +       * Recherche par le type d'​action d'//apt// 
 +       * Recherche possible dans les fichiers de logs archivés 
 +       * Affichage humainement lisible 
 +  * Script directement fonctionnel (pas de modification nécessaire).
  
 +<note warning>​Nécessite //gawk// et //zcat// : <code root>apt install gawk gzip</​code></​note>​
 ===== L'aide ===== ===== L'aide =====
-<​code>​Apt History Research - ahr+<​code>​Apt History Research - ahr - 2023-05-12-22:​05
 Usage : Usage :
    ​ahr ​   [-a | -z N] [--apt [-0]] [-c COMMAND] [-d DATE]  [-t TYPE]  MOTIF    ​ahr ​   [-a | -z N] [--apt [-0]] [-c COMMAND] [-d DATE]  [-t TYPE]  MOTIF
Ligne 51: Ligne 60:
                                                                        ​Tawal®©</​code>​                                                                        ​Tawal®©</​code>​
 ===== Le script ===== ===== Le script =====
-(mis à jour le 10/03/2023)+(mis à jour le 12/05/2023 22:05)
 <file bash ahr>#​!/​bin/​bash <file bash ahr>#​!/​bin/​bash
  
Ligne 60: Ligne 69:
 # Nécessite : gawk (apt install gawk) # Nécessite : gawk (apt install gawk)
 # #
-version=2023-03-10 +version=2023-05-12-22:05
 ### Répertoire des logs d'apt (personnalisable) ### Répertoire des logs d'apt (personnalisable)
 apt_folder="/​var/​log/​apt"​ apt_folder="/​var/​log/​apt"​
Ligne 78: Ligne 86:
  
 ### Fonctions ### Fonctions
-usage()+usage_quit()
 { {
-    echo -e "Apt History Research - ahr+    echo -e "Apt History Research - ahr -  $version
 Usage : Usage :
    ​${Surb}${0##​*/​} ​   [-a | -z N] [--apt [-0]] [-c COMMAND] [-d DATE]  [-t TYPE]  MOTIF${Rst}    ​${Surb}${0##​*/​} ​   [-a | -z N] [--apt [-0]] [-c COMMAND] [-d DATE]  [-t TYPE]  MOTIF${Rst}
Ligne 106: Ligne 114:
  
     -z, --dezip ${Surb}N${Rst} ​          ​Rechercher dans le fichier archive ${Surb}N${Rst} :     -z, --dezip ${Surb}N${Rst} ​          ​Rechercher dans le fichier archive ${Surb}N${Rst} :
-                              ${Ital}$apt_folder/​history.log.${Surb}N${Rst}.gz${Rst}+                              ${Ital}$apt_folder/​history.log.${Surb}N${Rst}${Ital}.gz${Rst}
                             Imcompatible avec '​${Ital}-a${Rst}'​.                             Imcompatible avec '​${Ital}-a${Rst}'​.
  
Ligne 128: Ligne 136:
 } }
  
-version()+version_quit()
 { {
     echo "​$version"​     echo "​$version"​
Ligne 134: Ligne 142:
 } }
  
-erreur()+erreur_quit()
 { {
     echo -n "​${0##​*/​} : "     echo -n "​${0##​*/​} : "
-    [ "​$1"​ = "​log"​ ]    && echo -e "Le fichier '​$apt_folder/​history.log'​ n'​existe pas."​ +    [ "​$1"​ = "​log"​ ]      && echo -e "Le fichier '​$apt_folder/​history.log'​ n'​existe pas."​ 
-    [ "​$1"​ = "​zip"​ ]    && echo -e "Le fichier '​$apt_folder/​history.log.$2.gz'​ n'​existe pas."​ +    [ "​$1"​ = "​zip"​ ]      && echo -e "Le fichier '​$apt_folder/​history.log.$2.gz'​ n'​existe pas."​ 
-    [ "​$1"​ = "​opt"​ ]    && echo -e "​Option ${Surb}'​$2'​${Rst} non-reconnue."​ +    [ "​$1"​ = "​opt"​ ]      && echo -e "​Option ${Surb}'​$2'​${Rst} non-reconnue."​ 
-    [ "​$1"​ = "​opt0"​ ]   ​&& echo -e "​Option '​${Surb}-0${Rst}'​ utilisée sans '​${Surb}--apt${Rst}'​."​ +    [ "​$1"​ = "​opt0"​ ]     ​&& echo -e "​Option '​${Surb}-0${Rst}'​ utilisée sans '​${Surb}--apt${Rst}'​."​ 
-    [ "​$1"​ = "​motif"​ ]  && echo -e "Motif absent ou pas d'​utilisation d'une des options '​${Surb}-c${Rst}'​ ou '​${Surb}-d${Rst}'​ ou '​${Surb}-t${Rst}'​."​ +    [ "​$1"​ = "​motif"​ ]    && echo -e "Motif absent ou pas d'​utilisation d'une des options '​${Surb}-c${Rst}'​ ou '​${Surb}-d${Rst}'​ ou '​${Surb}-t${Rst}'​."​ 
-    [ "​$1"​ = "​opt_az"​ ] && echo -e "​Options '​${Surb}-a${Rst}'​ et '​${Surb}-z${Rst}'​ incompatibles."​ +    [ "​$1"​ = "​opt_az"​ ]   ​&& echo -e "​Options '​${Surb}-a${Rst}'​ et '​${Surb}-z${Rst}'​ incompatibles."​ 
-    [ "​$1"​ = "​opt_z"​ ]  && echo -e "​L'​argument de l'​option ${Surb}'​-z'​${Rst} doit être un nombre."​ +    [ "​$1"​ = "​opt_z"​ ]    && echo -e "​L'​argument de l'​option ${Surb}'​-z'​${Rst} doit être un nombre."​ 
-    [ "​$1"​ = "​opt_t"​ ]  && echo -e "​L'​option ${Surb}-t${Rst} ne prend que les mots ${Surb}Install${Rst},​ ${Surb}Reinstall${Rst},​ ${Surb}Upgrade${Rst},​ ${Surb}Remove${Rst} et ${Surb}Purge${Rst}."​ +    [ "​$1"​ = "​opt_t"​ ]    && echo -e "​L'​option ${Surb}-t${Rst} ne prend que les mots ${Surb}Install${Rst},​ ${Surb}Reinstall${Rst},​ ${Surb}Upgrade${Rst},​ ${Surb}Remove${Rst} et ${Surb}Purge${Rst}."​ 
-    [ "​$1"​ = "​opt_d"​ ]  && echo -e "Date incorrecte : ${*:​2}"​+    [ "​$1"​ = "​opt_d"​ ]    && echo -e "Date incorrecte : ${*:​2}"​ 
 +    [[ $1 =~ gawk|zcat ]] && echo -e "​Nécessite ${Ital}${BASH_REMATCH[0]}${Rst} : apt install ${BASH_REMATCH[0]}"​ 
 +    ​
     exit 1     exit 1
 } >&2 } >&2
Ligne 161: Ligne 171:
 input2treat() input2treat()
 { {
-    local f n zap="​$1"​ +    local f n zap="​$1"​ 
-    declare -a LogFich+    declare -a LogFich ​idx
     shift     shift
  
     if [ "​$1"​ = "​all"​ ]     if [ "​$1"​ = "​all"​ ]
     then     then
-        z=$(find "​$apt_folder"​ -type f -name "​his*gz"​ | wc -l) 
         for f in "​$apt_folder"/​hist*gz         for f in "​$apt_folder"/​hist*gz
         do         do
             n="​${f%.*}";​ n="​${n##​*.}"​             n="​${f%.*}";​ n="​${n##​*.}"​
-            LogFich[$((z-n))]="​$f"​+            LogFich[n]="​$f"​
         done         done
-        ​for f in "${LogFich[@]}"+        ​# shellcheck disable=SC2206 
 +        idx=( ${!LogFich[@]} ​
 +        for ((i=${#​idx[@]}-1;​ i>=0; i--))
         do         do
-            zcat "$f"+            zcat "${LogFich[${idx[i]}]}"
         done         done
-        ​((zap)) && cat "​$apt_folder"/​history.log+        ​[ ! "$zap" ] && cat "​$apt_folder"/​history.log
  
     elif [ "​$1"​ = "​one"​ ]     elif [ "​$1"​ = "​one"​ ]
Ligne 193: Ligne 204:
     case $option in     case $option in
         a) opt_a="​on"​         a) opt_a="​on"​
-           [ "​$opt_z"​ ] && ​erreur ​opt_az+           [ "​$opt_z"​ ] && ​erreur_quit ​opt_az
            ​dezip_type="​all"​            ​dezip_type="​all"​
            ;;            ;;
Ligne 199: Ligne 210:
            ;;            ;;
         d) opt_d="​$OPTARG"​         d) opt_d="​$OPTARG"​
-           ​test_opt opt_d "​$opt_d"​ || erreur ​opt_d "​$opt_d"​+           ​test_opt opt_d "​$opt_d"​ || erreur_quit ​opt_d "​$opt_d"​
            ;;            ;;
         z) opt_z="​on"​         z) opt_z="​on"​
            [ "​$opt_a"​ ] && erreur opt_az            [ "​$opt_a"​ ] && erreur opt_az
-           ​test_opt opt_z "​$OPTARG"​ || erreur ​opt_z+           ​test_opt opt_z "​$OPTARG"​ || erreur_quit ​opt_z
            ​dezip_type="​one"​            ​dezip_type="​one"​
            ​dezip_nb="​$OPTARG"​            ​dezip_nb="​$OPTARG"​
            ;;            ;;
-        h) usage+        h) usage_quit
            ;;            ;;
         t) opt_t="​$OPTARG"​         t) opt_t="​$OPTARG"​
-           ​test_opt opt_t "​$opt_t"​ || erreur ​opt_t+           ​test_opt opt_t "​$opt_t"​ || erreur_quit ​opt_t
            ;;            ;;
-        v) version+        v) version_quit
            ;;            ;;
         0) opt_null="​on"​         0) opt_null="​on"​
Ligne 218: Ligne 229:
         -) case $OPTARG in         -) case $OPTARG in
                  all) opt_a="​on"​                  all) opt_a="​on"​
-                      [ "​$opt_z"​ ] && ​erreur ​opt_az+                      [ "​$opt_z"​ ] && ​erreur_quit ​opt_az
                       dezip_type="​all"​                       dezip_type="​all"​
                       ;;                       ;;
Ligne 227: Ligne 238:
                       ;;                       ;;
                 date) opt_d="​${!OPTIND}"​                 date) opt_d="​${!OPTIND}"​
-                      test_opt opt_d "​$opt_d"​ || erreur ​opt_d+                      test_opt opt_d "​$opt_d"​ || erreur_quit ​opt_d
                       OPTIND=$((OPTIND+1))                       OPTIND=$((OPTIND+1))
                       ;;                       ;;
Ligne 233: Ligne 244:
                       opt_z="​on"​                       opt_z="​on"​
                       [ "​$opt_a"​ ] && erreur opt_az                       [ "​$opt_a"​ ] && erreur opt_az
-                      test_opt opt_z ${!OPTIND} || erreur ​opt_z+                      test_opt opt_z ${!OPTIND} || erreur_quit ​opt_z
                       dezip_type="​one"​                       dezip_type="​one"​
                       dezip_nb=${!OPTIND}                       dezip_nb=${!OPTIND}
                       OPTIND=$((OPTIND+1))                       OPTIND=$((OPTIND+1))
                       ;;                       ;;
-                help) usage+                help) usage_quit
                       ;;                       ;;
                 type) opt_t=${!OPTIND}                 type) opt_t=${!OPTIND}
-                      test_opt opt_t "​$opt_t"​ || erreur ​opt_t+                      test_opt opt_t "​$opt_t"​ || erreur_quit ​opt_t
                       OPTIND=$((OPTIND+1))                       OPTIND=$((OPTIND+1))
                       ;;                       ;;
-             ​version) ​version+             ​version) ​version_quit
                       ;;                       ;;
-                   ​*) ​erreur ​opt --"​$OPTARG"​+                   ​*) ​erreur_quit ​opt --"​$OPTARG"​
                       ;;                       ;;
            esac            esac
            ;;            ;;
-        *) erreur ​opt -"​$OPTARG"​+        *) erreur_quit ​opt -"​$OPTARG"​
            ;;            ;;
     esac     esac
 done done
 shift $((OPTIND-1)) shift $((OPTIND-1))
 +
 +if ! hash gawk 2>​dev/​null
 +then
 +    erreur_quit gawk
 +fi
 +
 +if ! hash zcat 2>​dev/​null
 +then
 +    erreur_quit zcat
 +fi
  
 if [ "​$1"​ ] if [ "​$1"​ ]
Ligne 261: Ligne 282:
 elif [ ! "​$opt_c"​ ] && [ ! "​$opt_d"​ ] && [ ! "​$opt_t"​ ] elif [ ! "​$opt_c"​ ] && [ ! "​$opt_d"​ ] && [ ! "​$opt_t"​ ]
 then then
-    ​erreur ​motif+    ​erreur_quit ​motif
 fi fi
  
 if [ "​$opt_null"​ ] && [ ! "​$opt_apt"​ ] if [ "​$opt_null"​ ] && [ ! "​$opt_apt"​ ]
 then then
-    ​erreur ​opt0+    ​erreur_quit ​opt0
 fi fi
  
Ligne 277: Ligne 298:
         if [ "​$opt_a"​ ]         if [ "​$opt_a"​ ]
         then         then
-            zap=1+            zap="​on"​
         else         else
-            ​erreur ​log+            ​erreur_quit ​log
         fi         fi
     fi     fi
Ligne 288: Ligne 309:
 # shellcheck disable=SC1004 # shellcheck disable=SC1004
 gawk -vrech="​$rech"​ -vopt_c="​$opt_c"​ -vopt_d="​$opt_d"​ -vopt_t="​$opt_t" ​ -vapt="​$opt_apt"​ -vnull="​$opt_null"​ ' gawk -vrech="​$rech"​ -vopt_c="​$opt_c"​ -vopt_d="​$opt_d"​ -vopt_t="​$opt_t" ​ -vapt="​$opt_apt"​ -vnull="​$opt_null"​ '
 +    function afficher(verb,​ zero, mess, Array, ArrayTmp, tmp,    k,n) {
 +        if (0 in Array) {
 +            if (!verb && mess) {print mess}
 +            for (n in Array) {
 +                if (tmp && Array[n] ~ /,/) {
 +                    ArrayTmp[k++]=Array[n]
 +                    continue
 +                }
 +                if (!verb) {printf("​\t"​)}
 +                printf(Array[n])
 +                if (zero) {printf("​\0"​)}else{printf("​\n"​)}
 +            }
 +        }
 +    }
     BEGIN {     BEGIN {
         PROCINFO["​sorted_in"​]="​@val_str_asc"​         PROCINFO["​sorted_in"​]="​@val_str_asc"​
Ligne 368: Ligne 403:
                 if (demand) {print "​Demandeur ​  : ​ "​demand}                 if (demand) {print "​Demandeur ​  : ​ "​demand}
             }             }
-            if (0 in I) { + 
-                ​if ​(!apt) {print ​"​Installés :"+            ​afficher(apt, null, "​Installés :"I, Itmp"on") 
-                for (w in I) { +            ​afficher(apt, null, ""​Itmp) 
-                    if (I[w] ~ /,/) { +            ​afficher(apt, null, "​Upgradés :"U) 
-                        ​Itmp[l++]=I[w] +            ​afficher(aptnull"​Désinstallés :"R) 
-                        continue +            ​afficher(aptnull"​Purgés :"P) 
-                    } +            ​afficher(aptnull"​Réinstallés :"Re) 
-                    if (!apt) {printf("\t")+
-                    printf(I[w]) +
-                    if (null) {printf("​\0"​)}else{printf("​\n"​)} +
-                } +
-            } +
-            ​if (0 in Itmp) { +
-                for (tmp in Itmp) { +
-                    if (!apt) {printf("\t")} +
-                    printf(Itmp[tmp]) +
-                    if (null) {printf("​\0"​)}else{printf("​\n"​)} +
-                } +
-            ​+
-            if (0 in U) { +
-                if (!apt) {print ​"​Upgradés :"+
-                for (x in U) { +
-                    ​if ​(!apt) {printf("​\t"​)} +
-                    printf(U[x]) +
-                    if (null) {printf("​\0"​)}else{printf("​\n"​)} +
-                } +
-            } +
-            if (0 in R) { +
-                if (!apt) {print ​"​Désinstallés :"+
-                for (y in R) { +
-                    ​if ​(!apt) {printf("​\t"​)} +
-                    printf(R[y]) +
-                    if (null) {printf("​\0"​)}else{printf("​\n"​)} +
-                } +
-            } +
-            if (0 in P) { +
-                if (!apt) {print ​"​Purgés :"+
-                for (z in P) { +
-                    ​if ​(!apt) {printf("​\t"​)} +
-                    printf(P[z]) +
-                    if (null) {printf("​\0"​)}else{printf("​\n"​)} +
-                } +
-            } +
-            if (0 in Re) { +
-                if (!apt) {print ​"​Réinstallés : "+
-                for (w in Re) { +
-                    if (!apt) {printf("​\t"​)} +
-                    printf(Re[w]) +
-                    if (null) {printf("​\0"​)}else{printf("​\n"​)} +
-                } +
-            }+
             if (!apt) {             if (!apt) {
                 if (a>1) {s1="​s"​}else{s1=""​}                 if (a>1) {s1="​s"​}else{s1=""​}
Ligne 436: Ligne 428:
             date=""​             date=""​
             demand=""​             demand=""​
-            a=0; b=0; c=0; d=0; e=0; ok=0; ok1=0; l=0+            a=0; b=0; c=0; d=0; e=0; ok=0; ok1=0
         }         }
     }     }
Ligne 442: Ligne 434:
  
 ===== Exemples d'​utilisation et de retours ===== ===== Exemples d'​utilisation et de retours =====
 +
 +=== Afficher tout l'​historique (archives comprises) ===
 +<code user>ahr -a .</​code>​
 +
 === Afficher l'​historique non archivé concernant un paquet === === Afficher l'​historique non archivé concernant un paquet ===
 <code user>ahr youtube-dl</​code>​ <code user>ahr youtube-dl</​code>​
Ligne 485: Ligne 481:
  youtube-dl:​amd64 (2021.06.06-1,​ 2021.12.17-1~bpo11+1)  youtube-dl:​amd64 (2021.06.06-1,​ 2021.12.17-1~bpo11+1)
 1 paquet upgradé 1 paquet upgradé
 +</​code>​
  
- +=== Afficher l'​historique des désinstallations d'​unattended-upgrade dans le fichier archive 1 === 
-Date Début ​ :  2023-03-03 16:14:48 +<code user>ahr -c unattended -t Remove -z1</​code>​ 
-Date Fin    :  2023-03-03 16:15:43 +<​code>​ 
-Commande ​   :  ​apt install gnustep-base-runtime+Date Début ​ :  2023-04-29 23:34:02 
 +Date Fin    :  2023-04-29 23:34:23 
 +Commande ​   :  ​/​usr/​bin/​unattended-upgrade
 Demandeur ​  : ​ tawal (1000) Demandeur ​  : ​ tawal (1000)
-Installés ​+Désinstallés ​
- gnustep-base-runtime:​amd64 (1.27.0-3) + linux-headers-5.10.0-20-amd64:amd64 (5.10.158-2) 
- gnustep-base-common:amd64 (1.27.0-3, automatic) +paquet désinstallé
- gnustep-common:​amd64 (2.8.0-1, automatic+
- libgnustep-base1.27:​amd64 (1.27.0-3, automatic) +
- libobjc4:​amd64 (10.2.1-6, automatic) +
-5 paquets installés+
  
  
-Date Début ​ :  2023-03-03 21:20:23 +Date Début ​ :  2023-04-29 23:34:38 
-Date Fin    :  2023-03-03 21:20:54 +Date Fin    :  2023-04-29 23:34:48 
-Commande ​   :  ​apt install parole +Commande ​   :  ​/​usr/​bin/​unattended-upgrade 
-Demandeur ​   tawal (1000) +Désinstallés ​
-Installés : + linux-headers-5.10.0-20-common:amd64 (5.10.158-2
- parole:amd64 (4.16.0-1+1 paquet ​désinstallé
-1 paquet ​installé+
  
  
-Date Début ​ :  2023-03-03 22:08:48 +Date Début ​ :  2023-04-29 23:35:05 
-Date Fin    :  2023-03-03 22:09:42 +Date Fin    :  2023-04-29 23:35:41 
-Commande ​   :  ​apt install ​/home/tawal/Téléchargements/​yt-dlp_2023.02.17-1_all.deb +Commande ​   :  /usr/bin/unattended-upgrade 
-Demandeur ​   tawal (1000) +Désinstallés ​
-Upgradés : + linux-image-5.10.0-20-amd64:​amd64 (5.10.158-2
- yt-dlp:amd64 (2023.02.17-1~bpo11+1, 2023.02.17-1) +1 paquet ​désinstallé
-1 paquet upgradé +
- +
- +
-Date Début ​ :  2023-03-03 22:38:04 +
-Date Fin    :  2023-03-03 22:38:31 +
-Commande ​   :  apt remove --purge yt-dlp +
-Demandeur ​  : ​ tawal (1000) +
-Purgés : +
- yt-dlp:amd64 (2023.02.17-1) +
-1 paquet purgé +
- +
- +
-Date Début ​ :  2023-03-03 22:39:03 +
-Date Fin    :  2023-03-03 22:39:34 +
-Commande ​   :  apt install yt-dlp +
-Demandeur ​  : ​ tawal (1000) +
-Installés : +
- yt-dlp:amd64 (2023.02.17-1~bpo11+1) +
-1 paquet installé +
- +
- +
-Date Début ​ :  2023-03-04 11:01:19 +
-Date Fin    :  2023-03-04 11:01:53 +
-Commande ​   :  apt install weechat-doc +
-Demandeur ​  : ​ tawal (1000) +
-Installés : +
- weechat-doc:​amd64 (3.0-1+deb11u1+
-1 paquet ​installé+
 </​code>​ </​code>​
utilisateurs/tawal/scripts/apt-history-research.txt · Dernière modification: 08/06/2023 22:38 par Tawal

Pied de page des forums

Propulsé par FluxBB