I am using a bash script that calls screen hardcopy -h to copy the contents of a catted logfile to terminal output, but when the log file includes GRUB Menu for example, the resulting output file contains null characters amongst other characters such as ^B, ^L, ^P.
Here is part of the script that handles converting the log files:
export input_file
export output_file
export scrollback_size
#Calls a detached screen session specifying /dev/null file, inside the
#screen session cat the log to the terminal and copy the
#scrollback contents to the output file
screen -Dmc /dev/null sh -c '
screen -X scrollback "$scrollback_size"
cat < "$input_file"
screen -X hardcopy -h "$output_file"'
Here is a sample input logfile that contains GRUB MENU:
Booting /efi\boot\bootaa64.efi
[0;30;47m[?25hWelcome to GRUB!
[0;37;40m[0;37;40m[0;37;40msmc911x: detected LAN9220 controller
smc911x: phy initialized
smc911x: MAC 00:02:f7:00:8a:08
[?25l[0;37;40m[0;37;40m[2J[1;1H[0;37;40m[2;49HGNU GRUB version 2.11
[0;37;40m[4;2H┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐[5;2H│[5;117H│[6;2H│[6;117H│[7;2H│[7;117H│[8;2H│[8;117H│[9;2H│[9;117H│[10;2H│[10;117H│[11;2H│[11;117H│[12;2H│[12;117H│[13;2H│[13;117H│[14;2H│[14;117H│[15;2H│[15;117H│[16;2H│[16;117H│[17;2H│[17;117H│[18;2H│[18;117H│[19;2H│[19;117H│[20;2H│[20;117H│[21;2H│[21;117H│[22;2H│[22;117H│[23;2H│[23;117H│[24;2H│[24;117H│[25;2H│[25;117H│[26;2H│[26;117H│[27;2H│[27;117H│[28;2H│[28;117H│[29;2H│[29;117H│[30;2H│[30;117H│[31;2H│[31;117H│[32;2H│[32;117H│[33;2H│[33;117H│[34;2H│[34;117H│[35;2H│[35;117H│[36;2H│[36;117H│[37;2H│[37;117H│[38;2H│[38;117H│[39;2H│[39;117H│[40;2H│[40;117H│[41;2H│[41;117H│[42;2H│[42;117H│[43;2H│[43;117H│[44;2H│[44;117H│[45;2H│[45;117H│[46;2H└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘[0;37;40m[47;2H[48;2H[0;37;40m Use the ▲ and ▼ keys to select which entry is highlighted.
Press enter to boot the selected OS, `e' to edit the commands before booting or `c' for a command-line. [5;118H [0;37;40m[5;3H Linux BusyBox [0;37;40m[5;116H[0;37;40m[0;30;47m[6;3H*bbr/bsa [0;37;40m[6;116H[0;37;40m[0;37;40m[7;3H [0;37;40m[7;116H[0;37;40m[0;37;40m[8;3H [0;37;40m[8;116H[0;37;40m[0;37;40m[9;3H [0;37;40m[9;116H[0;37;40m[0;37;40m[10;3H [0;37;40m[10;116H[0;37;40m[0;37;40m[11;3H [0;37;40m[11;116H[0;37;40m[0;37;40m[12;3H [0;37;40m[12;116H[0;37;40m[0;37;40m[13;3H [0;37;40m[13;116H[0;37;40m[0;37;40m[14;3H [0;37;40m[14;116H[0;37;40m[0;37;40m[15;3H [0;37;40m[15;116H[0;37;40m[0;37;40m[16;3H [0;37;40m[16;116H[0;37;40m[0;37;40m[17;3H [0;37;40m[17;116H[0;37;40m[0;37;40m[18;3H [0;37;40m[18;116H[0;37;40m[0;37;40m[19;3H [0;37;40m[19;116H[0;37;40m[0;37;40m[20;3H [0;37;40m[20;116H[0;37;40m[0;37;40m[21;3H [0;37;40m[21;116H[0;37;40m[0;37;40m[22;3H [0;37;40m[22;116H[0;37;40m[0;37;40m[23;3H [0;37;40m[23;116H[0;37;40m[0;37;40m[24;3H [0;37;40m[24;116H[0;37;40m[0;37;40m[25;3H [0;37;40m[25;116H[0;37;40m[0;37;40m[26;3H [0;37;40m[26;116H[0;37;40m[0;37;40m[27;3H [0;37;40m[27;116H[0;37;40m[0;37;40m[28;3H [0;37;40m[28;116H[0;37;40m[0;37;40m[29;3H [0;37;40m[29;116H[0;37;40m[0;37;40m[30;3H [0;37;40m[30;116H[0;37;40m[0;37;40m[31;3H [0;37;40m[31;116H[0;37;40m[0;37;40m[32;3H [0;37;40m[32;116H[0;37;40m[0;37;40m[33;3H [0;37;40m[33;116H[0;37;40m[0;37;40m[34;3H [0;37;40m[34;116H[0;37;40m[0;37;40m[35;3H [0;37;40m[35;116H[0;37;40m[0;37;40m[36;3H [0;37;40m[36;116H[0;37;40m[0;37;40m[37;3H [0;37;40m[37;116H[0;37;40m[0;37;40m[38;3H [0;37;40m[38;116H[0;37;40m[0;37;40m[39;3H [0;37;40m[39;116H[0;37;40m[0;37;40m[40;3H [0;37;40m[40;116H[0;37;40m[0;37;40m[41;3H [0;37;40m[41;116H[0;37;40m[0;37;40m[42;3H [0;37;40m[42;116H[0;37;40m[0;37;40m[43;3H [0;37;40m[43;116H[0;37;40m[0;37;40m[44;3H [0;37;40m[44;116H[0;37;40m[0;37;40m[45;3H [0;37;40m[45;116H[0;37;40m[45;118H [6;116H[50;1H The highlighted entry will be executed automatically in 5s. [6;116H[50;1H The highlighted entry will be executed automatically in 4s. [6;116H[50;1H The highlighted entry will be executed automatically in 3s. [6;116H[50;1H The highlighted entry will be executed automatically in 2s. [6;116H[50;1H The highlighted entry will be executed automatically in 1s. [6;116H[50;1H The highlighted entry will be executed automatically in 0s. [6;116H[?25h[0;37;40m[2J[1;1H[0;37;40m
Booting `bbr/bsa'
/EndEntire
Here are the differences in outputs that I am referring to: manually copying the terminal output after catting the input file Versus the script's "incorrect" output
I am wondering why screen hardcopy is unable to "replicate" this grub menu and instead outputs NULL characters amongst others? I am probably going to add a command that scrubs the file of these characters but I would like a solution that can implement them just as they are in the manual copy method.