A customer recently contacted us regarding fixing "strace: exec: Exec format error". You will see how we solved this problem in this tutorial.
As part of our Server Support Services, we have helped customers resolved Linux related errors.
In this context, we shall see how to get rid of this issue.
More about strace exec: Exec format error to occur
Strace is a very essential command for troubleshooting. In some scenarios, a Linux user might experience strace exec: Exec format error when the strace command cannot complete its executable script process in relation to the shell responsible for such an execution. When this error occurs, you will see an error message such as;
How to solve strace exec: Exec format error
We had a customer who ran the strace command below and got errors;
strace -ae -o /tmp/output.log ./ocmstart.sh
strace: exec: Exec format error
We noticed that the shell was not referenced in the execution process and thus we applied it as seen on the command below;
strace -ae -o /tmp/output.log $SHELL ./ocmstart.sh
What was done here is that the script is being executed with the default user shell thereby giving strace access to use the binary file process to make it work without any further obstruction.
In another scenario, the customer did not use the shebang attribute at the beginning of the script. Shebang contains #! characters. To make this work, it is recommended to use the shebang attribute #!/bin/bash at the beginning of the script to enable the kernel to understand the command.