le script utilise systemd :
journalctl --list-boots
, le rapport est uniquement pour un mois donné; il faut donner obligatoirement en paramètre l'année et le mois : boot-stats.sh "2015-08"
, boot-stats.sh "2015-12"
script boot-stats.sh :
#!/usr/bin/env bash
# fichier : boot-stats.sh [ yyyy-mm ]
param="$1" # format 2015-11
total=0
difference() {
local diff=$(($2-$1))
((total+=diff/60))
}
declare -a dates
declare -a jours
journalctl --list-boots | grep -Eo " [a-z]{3}\. ${param}.*" | sed -e 's/CEST—/CEST ;/' -e 's/CET—/CET ;/' -e 's/[a-z].//g'>/tmp/boot-stats
while IFS=';' read a b; do
echo "-- $a --> $b"
j="${a:10:2}"
((j=${j#0}+0))
jours[$j]=$j
difference "$(date -d "$a" +%s)" "$(date -d "$b" +%s)"
done < /tmp/boot-stats
nbjours="${#jours[@]}"
((total/=60))
echo "$((total)) heures"
((nbjours>0)) && echo "$((total/${nbjours})) heures /jour (${nbjours} jours)"
echo "Utilisée ${#jours[@]} jours, les ${jours[*]} de ce mois"
rm /tmp/boot-stats &>/dev/null