Log console output from the stackscript
I have deployed my Linode with stackscript without problem, but I'm looking for a way to log all the console output from the stackscript to a file, so I can review the log after the deploy finished.
I have been trying tools like "script", "ttylog"(from cpanm), but they seems not work on logging the output from hvc0.
I also tried "lastcomm"(from acct) which can list the commands have been executed, but it just not exactly what I need.
So any idea?
Thanks.
4 Replies
exec >/path/to/log/file
This will capture standard output
exec >/path/to/log/file 2>&1
Edit: the above will clobber the log file if it already exists. To append to the file instead, use
exec >>/path/to/log/file 2>&1
I knew the way you're talking about, but I'm looking for the way to save the console message without touch the original commands.
Thanks.
Expecting people to add ONE WHOLE LINE to an existing script - what world do you live in???
Here is what I am using in a StackScript to send stdout and stderr to a log file and also to console (so the progress can be viewed in lish):
# send stdout and stderr to both console and log file
>/root/stackscript.log
exec > >(tee -a /root/stackscript.log)
exec 2> >(tee -a /root/stackscript.log >&2)
This may help someone else.