mr_freeze.sh a tool to compare commands output from the past

-

./mr_freeze.sh (freeze|thaw|prior_result) input

Blogpost-documentation generated by using ./mr_freeze.sh usage as a way to try to have all in one place ;)

Source here : https://gist.github.com/jul/ef4cbc4f506caace73c3c38b91cb1ea2

A utility for comparing present scripts execution with past output

Action

freeze input

record the script given in input with ONE INSTRUCTION PER LINE to compare result for future use.

Except when **_OUTPUT** is set, output will automatically redirected to replay_${input}

thaw input

replay the command in input (a frozen script output) and compare them with past result

prior_result input

show the past recorded value in the input file

Quickstart

The code comes with its own testing data that are dumped in input

It is therefore possible to try the code with the following input :

$ PROD=1 ./mr_freeze.sh freeze input "badass" "b c"

to have the following output

✍️ recording: uname -a #immutable
✍️ recording: [ -n "$PROD" ] && echo "ok" || echo "ko" # mutable according to env variable
✍️ recording: date # mutable
✍️ recording: slmdkfmlsfs # immutable
✍️ recording: du -sh #immutable (kof kof)
✍️ recording: ssh "$A"  'uname -a'
✅ [input] recorded. Use [./mr_freeze.sh thaw "replay_input" "badass" "b c"] to replay

ofc, it works because I have a station called badass with an ssh server.

and then check what happens when you thaw the file accordingly.

$ ./mr_freeze.sh thaw "replay_input" "badass" "b c"

You have the following result:

👌 uname -a #immutable
🔥 [ -n "$PROD" ] && echo "ok" || echo "ko" # mutable according to env variable
@@ -1 +1 @@
-ok
+ko
🔥 date # mutable
@@ -1 +1 @@
-lun. 10 nov. 2025 20:21:14 CET
+lun. 10 nov. 2025 20:21:17 CET
👌 slmdkfmlsfs # immutable
👌 du -sh #immutable (kof kof)
👌 ssh "$A"  'uname -a'

Which means the commands replayed with same output except date and the code checking for the env variable PROD and there is a diff of the output of the command.

Since the script is using subtituable variables ($3 … $10) being remapped to ($A … $H)

We can also change the target of the ssh command by doing :

$   PROD=1 ./mr_freeze.sh thaw "replay_input" "petiot"

which gives:

👌 uname -a #immutable
👌 [ -n "$PROD" ] && echo "ok" || echo "ko" # mutable according to env variable
🔥 date # mutable
@@ -1 +1 @@
-lun. 10 nov. 2025 20:21:14 CET
+lun. 10 nov. 2025 20:22:30 CET
👌 slmdkfmlsfs # immutable
👌 du -sh #immutable (kof kof)
🔥 ssh "$A"  'uname -a'
@@ -1 +1 @@
-Linux badass 6.8.0-85-generic #85-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep 18 15:26:59 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
+FreeBSD petiot 14.3-RELEASE-p5 FreeBSD 14.3-RELEASE-p5 GENERIC amd64

It’s also possible to change the output file by using _OUTPUT like this :

$ _OUTPUT=this ./mr_freeze.sh freeze input   badass

which will acknowledge the passed argument :

✅ [input] created use [./mr_freeze.sh thaw "this" "badass"] to replay

And last to check what has been recorded :

$ ./mr_freeze.sh prior_result this

which gives :

👉 uname -a #immutable
Linux badass 6.8.0-85-generic #85-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep 18 15:26:59 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Status:0
--------------------------------------------------------------------------
👉 [ -n "$PROD" ] && echo "ok" || echo "ko" # mutable according to env variable
ok
Status:0
--------------------------------------------------------------------------
👉 date # mutable
lun. 10 nov. 2025 20:21:14 CET
Status:0
--------------------------------------------------------------------------
👉 slmdkfmlsfs # immutable
./mr_freeze.sh: ligne 165: slmdkfmlsfs : commande introuvable
Status:127
--------------------------------------------------------------------------
👉 du -sh #immutable (kof kof)
308K .
Status:0
--------------------------------------------------------------------------
👉 ssh "$A"  'uname -a'
Linux badass 6.8.0-85-generic #85-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep 18 15:26:59 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Status:0
--------------------------------------------------------------------------