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?


4 Replies

Somewhere in the stackscript before the output you want to capture, you can add the following line:

exec >/path/to/log/file

This will capture standard output. If you want to capture standard error as well, use

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.


Yeah Vance, it needs to be a magic way, geeeesh, didn't you learn anything from those 8 nauseating Harry Potter movies? (ok, the first three were kind of cute, then the actors/actresses turned 35 and kind of spoiled the whole suspend disbelief thing).

Expecting people to add ONE WHOLE LINE to an existing script - what world do you live in???

Old thread but it comes up highest in search results when I was trying to achieve the same.

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
exec >  >(tee -a /root/stackscript.log)
exec 2> >(tee -a /root/stackscript.log >&2)

This may help someone else.


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct