I am trying to use script command for logging a bash session.
The script command is executed from withing a bash script but as soon as it is executed, the bash script terminates.
I have tried to invoke the command using various combination always with the same result (termination of the bash script as soon as the command is called). The output that I get is the following:
Script started, file is typescript
root@ubuntu: ...
I have also tried to invoke the command with an & in the end but again with no luck.
Can anyone tell me how should I invoke the command from a bash script?
Thanks
Your shell script did not terminate. It is still running. You are getting a prompt because
scriptis spawning a new shell. the prompt you see is the prompt from the spawned shell.The normal use case for
scriptis something like this:script. this spawns a new shell.scriptSo basically
scriptis working as expected. You will have to find another way to achieve what you want.You can log the execution of your script like this:
Explanation:
exec > logfile 2>&1redirects stdout and stderr to logfileset -xmakes bash print every command before executing itExample:
Disadvantage of this method is that the script prints no output for humans to see. Everything goes to the logfile.
Alternatively you can do it like this:
Then execute like this:
now output is directly visible and also saved to logfile (default name of logfile is
typescript)