Reputation: 277
The script
command executes and records logs.
( http://www.computerhope.com/unix/uscript.htm )
( http://linuxers.org/article/script-command-line-tool-recordsave-your-terminal-activity )
I use script
command for saving commands and those output.
Whenever using 'script', I type commands like followings.
$ script result.log
Script started, file is result.log
$ date
$ ls -la.
$ exit
Sometimes I want to use those command with shell script.
So I run like following.
$ script -c test.sh result.log
But the result.log has only output, it doesn't contain command itself. I want the result.log to include commands and output.
How can I do it?
Thanks
Upvotes: 4
Views: 459
Reputation: 1523
set -o verbose
Execute this on terminal before executing your script or add this at the beginning of the script.
This will change the terminal configuration to echo all the commands before executing them.
This will add the command then followed by the output of that command.
you can also use :
set -x or set -v set -xv
-x option enables variable expansion and echo's all the option used with the command.
-v is similar to -o verbose this simply echo's the command name
-xv echo's both.
Upvotes: 0
Reputation: 2776
if you use sh -x to run your script it will print the commands or add set -x to your script.
script -c "sh -x ./test.sh" reult.log
sample output:
+ date
Tue Dec 23 09:52:22 CET 2014
+ ls -la
Upvotes: 3