StackScript Logs

Presumably there are logs kept on the target instance that contain the STDOUT and STDERR of the StackScript when run. If so, where? If not, why not?

Sorry if I missed the answer and it's here. Couldn't find it, in that case.

WeAreHugh

6 Replies

StackScripts don't log by default, but you can enable logging in a variety of ways such as using logger or something like exec >/root/stackscript.log 2>&1 There's an excellent post here with some StackScript tips and tricks.

Stackscripts launch with stdin, stdout, and stderr connected to the console (whether that is /dev/console or /dev/ttyS0 is pretty irrelevant, as writing to either of them will go to the same place). If you want to save logs in your Stackscript, then you can either redirect program output to the logfile, or if your script is shell, you can use exec to replace the script's stdout and stderr with the file descriptor for the log file, which would then be inherited by any programs the script calls. (You can also do this replacement in other languages, generally speaking.)

@dwfreed - you got the gist of my question, and your suggestion regarding exec is right on, but it doesn't work. Possibly because the filesystem is initramfs when the machinations with getty are performed?

Anyway, as you suspected, what I would like to do is something like shebang:

#!/bin/bash >/root/SSout 2>/root/SSerr

and that would work in a normal bash script, but it doesn't work here. Nor do the lines:

1>/root/SSout
2>/root/SSerr

Worse, attempts like these to redirect cut off display in lish (hence my thought output might be going to initramfs).

I chose /root because that's where the StackScript shows up when creation is complete. In case there was a permissions problem, I also tried /tmp to no avail.

WeAreHugh

The getty is not launched (and thus the stackscript) until long after the root filesystem has been switched from the initramfs to the real root filesystem. Shebang lines are not processed for redirections, as that is a function of shell, not program execution. Adjusting the exec command @mjones gave for your particular file paths, this is what the start of your script could look like:

#!/bin/bash
exec >/root/SSout 2>/root/SSerr

dowork

Aye lads, twas the syntax. Thank ye for bein' there in the wee hours of me timezone!

Thanks @mjones and @dwfreed - still looking at why my first attempt with @mjones syntax didn't work but it did just now exactly as in @dwfreed's quote. Might have been the wee hour. And thanks for the lucid dialog @dwfreed.

Mission accomplished!

WeAreHugh

For readers:

This has the advantage of allowing remote collection of installation info, and, in the case of StackScripts that take a long time to complete, you can in terminal windows tail the progress:

#tail -f /root/SSout

and

#tail -f /root/SSerr

WeAreHugh

Reply

Please enter an answer
Tips:

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