Given: Linux is booted in recovery mode and it will wait for the user to select the options to select e.g. root, network, dpkg, fsck etc.
and then we have to write a script (prefer python) should choose one of the option
that is enable root and execute few commands and save/send to external IP the outputs received.
this script we can enable as by default service in systemd or so.
Check photo: Linux wait at this moment for user to select, and think if we don't have keyboard to select it but script running