Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I know that there is a way to write bash shell outputs to a file. However, I want to know what commands have been executed by an application as some of these executions are not outputted as a shell output.

So, is there a way to write commands, including outputs, that were executed to a file?

share|improve this question

2 Answers 2

if you run a bash script by calling it with:

bash -x yourbashscript.sh

you will see both the commands and the output give by the commands run.

share|improve this answer

If you execute your script with -x (e.g. bash -x <script>) you will see every output. If you want to run it normally without seeing the output (but redirect it to a file too), you can do bash -x <script> 2>/dev/null

Normally the -x bit prints to stderr (2) and not stdout (1).

You could set -x from within the script where you want to (and set +x when not) and redirect all STDERR to a file like above (scriptname.bash 2>coolfile.txt).

Much beyond that, you'll need to resort to perl or python.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.