From 1e097521714b3100a481cc38ac643a17aea3a925 Mon Sep 17 00:00:00 2001 From: Michel Le Cocq Date: Mon, 17 Mar 2025 07:28:30 +0100 Subject: [PATCH] ajout fonction output maintenant tout va dans un fichier log --- upsnapz.sh | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/upsnapz.sh b/upsnapz.sh index fded8d7..3324b21 100755 --- a/upsnapz.sh +++ b/upsnapz.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Time-stamp: <2025-03-15 06:55:37 nomad> +# Time-stamp: <2025-03-17 07:11:59 nomad> # Michel Le Cocq # @@ -22,7 +22,7 @@ # tunable variable # /!\ il faut ecrire ce fichier dans le vol bootfs sinon ca a peu d'interet -LOG_FILE=/root/upsnapz.log +LOG_FILE=./upsnapz.log # Dependencies : # - gh @@ -37,11 +37,18 @@ LOG_FILE=/root/upsnapz.log # - verfier que 'gh auth status' fonctionne avant de l'utiliser (auth) # - ameliorer l'integration de : apt full-upgrade # la c'est un peu brouillon et entraine de multiples question de snapshots -# - 2 souci avec tee et les logs dans un fichier : -# - perte couleurs -# - impossible de repondre aux questions de apt tpe : (Y/I/N/O/D/Z) [default=N] ? # +------------------------------------------------------------------------------------------------+ +output() +{ + # usage : output file command + # fonction pour afficher sur la sortie standard et envoyer dans un fichier log + output_file=$1 + shift + command=$@ + script -aefq $output_file -c "$command" +} + function showsnap { # fonction qui affiche le nombre de snap par rapport a chaques bootfs @@ -51,6 +58,10 @@ function showsnap # - du coup tout est commenté zfs list -o name,used,usedbysnapshots -r zroot/ROOT -s creation | grep -v '^zxroot/ROOT .*' > /tmp/upsnap.tmp + + # test de fonction output (sans doute a supprimer) + #output $LOG_FILE zfs list -o name,used,usedbysnapshots -r zroot/ROOT -s creation | grep -v '^zxroot/ROOT .*' + # for line in $(cat /tmp/upsnap.tmp | grep zroot | cut -d' ' -f1) # do # z='' @@ -276,8 +287,11 @@ function asksnap() then snapname=$(date +%Y-%m-%d-%H%M%S) sudo zfs snapshot $bootfs@$snapname - #sudo date +%Y_%m_%d-%H:%M > $LOG_FILE - zfs list -H -o name $bootfs@$snapname # | tee -a $LOG_FILE + + date +%Y_%m_%d-%H:%M > $LOG_FILE + output $LOG_FILE zfs list -H -o name $bootfs@$snapname + output $LOG_FILE zfs list -H -o name $bootfs@$snapname + askpromote $snapname $bootfs else echo no @@ -305,8 +319,8 @@ function askupgrade() # else # ask for making a snapshot - printf '\n%s\n' 'apt list --upgradable' #| tee /tmp/upsnapz-upgradable - apt list --upgradable #| tee -a /tmp/upsnapz-upgradable + output $LOG_FILE printf '\n%s\n' 'apt list --upgradable' + output $LOG_FILE apt list --upgradable printf '\nUpgrade or not : [Y-n]' read answer @@ -321,19 +335,19 @@ function askupgrade() then if [ $1 -eq 1 ] then - echo '\nAbove packages need full upgrade.\nRun full-upgrade :' \ - # | tee -a /tmp/upsnapz-upgradable - sudo apt -y full-upgrade # | tee -a /tmp/upsnapz-upgradable + output $LOG_FILE echo '\nAbove packages need full upgrade.\nRun full-upgrade :' + output $LOG_FILE sudo apt -y full-upgrade elif [ $1 -eq 0 ] then printf 'before upgrade : ' asksnap - printf '%s\n' 'apt -y upgrade' - sudo apt -y upgrade # | tee -a /tmp/upsnapz-upgradable + output $LOG_FILE printf '%s\n' 'apt -y upgrade' + output $LOG_FILE sudo apt -y upgrade fi - #sudo cat /tmp/upsnapz-upgradable >> $LOG_FILE else - echo no + output $LOG_FILE echo 'apt -y upgrade' + output $LOG_FILE echo 'no upgrade ... bye' + exit 1 fi }