Is there an easy way to log all activity that a shell script does?

There is a very easy and handy way:

Using script to make typescript of terminal session

  1. Start the command script

    If the argument file is given, eg script ~/tmp/output, script saves the dialogue in this file. If no filename is given, the dialogue is saved in the file typescript

  2. Start your script or what ever you want to start

  3. If your script is finished, stop script via Ctrl-D

  4. Check the output in the default output file typescript


To start your command in one step with script, use the parameter -c

-c COMMAND
    Run the COMMAND rather than an interactive 
    shell. This makes it easy for a script to capture
    the output of a program that behaves differently
    when its stdout is not a tty.

The usage of scriptinside your script makes no sense because script forks the shell or starts a new shell.

If the variable SHELL exists, the shell forked by script will be that shell. If SHELL is not set, the Bourne shell is assumed. (Most shells set this variable automatically).


if you normally run your script with foo.sh, try running it (assuming it's a bash script) with bash -x foo.sh. If you want everything redirected to file, try bash -x foo.sh > file.log 2>&1 (note I'm redirecting stderr as well, remove the 2>&1 if you don't want this). If you also want to see what's going on, bash -x foo.sh 2>&1 | tee file.log.