I have a linux system that uses lots of bash scripts as the bootup scripts. I want to print all the bash statements that are being executed in order to debug some issue. How can I do that at system-wide level?
I had the following as init
in my system :
$ls -la /init
lrwxrwxrwx. 1 root root 20 Feb 10 04:46 /init -> /lib/systemd/systemd
I replaced init
with a script like below :
#!/bin/bash
set -x
/lib/systemd/systemd
but no prints.
CodePudding user response:
Download bash sources, change https://github.com/bminor/bash/blob/f3a35a2d601a55f337f8ca02a541f8c033682247/flags.c#L88 to echo_command_at_execute = 1
. echo_command_at_execute
might be reset somewhere later, in reset_shell_flags()
and with change_flag('x', 0)
- make echo_command_at_execute
const
and remove all assignments to it. Recompile and install. Create sh -> bash
symlinks appriopriate for your system.
Note, that some scripts may parse stderr output of some shell programs. This modification may result in unstable system.
CodePudding user response:
Copy /bin/bash
to for example /bin/bash2
, and similar with sh
. Create an executable script:
#!/bin/bash2
/bin/bash2 -x "$@"
Repeat the process for sh
. The paths have to be absolute.
Note, that for initrd you will have to regenerate it and include the copied executables and the scripts in the image. the copied executables in the image. Research your distribution specific ways about generating initrd.
CodePudding user response:
I give an idea that do not confirm:
mv /bin/bash /bin/bashx
vi /bin/bash
set -x
/bin/bashx $@