Output of bash commands in snap hook

Hello together

I’m currently trying to figure out why a command doesn’t work in a pre-refresh hook from a snap. The commands are basic shell commands and I’m curious how to get the to the output of those commands.

Like standard out and error out, as you would sit in the bash.
I checked this:

As well as this:

There it mentiones debuggin a snap in the bash, but my snap has no “subcommands”, like snap run --shell mysnap.mycommand from the debugging documentation.

We checked the journal but it holds only the violations.

Can you please tell me how to reach those command outputs?

Thank you and greetings


stdout and stderr of hooks are pointing to the systemd journal (or syslog) usually … just start a seccond terminal and run journalctl -f in it while installing (or refreshing) the snap

Thanks for your reply. I just tested this again and the journalctl holds no logs or outputs from this hook at all (did exactly as you told me on a fresh install). I can see audit and other messages inside the journal, but nothing from the hook bashcript. The bashscript is executed, some of the code inside the bashscript works, some of the code not.

By the way it is a gadget snap, and I didnt install it in “–devmode” . I added set +x and set -x inside the script to see what its doing.

Any idea why, do I need to enable something in advance?

The output of hooks generally is only shown when the hook fails, otherwise you can see the output from hooks via snap tasks <chg> for a change that ran the hook

oops, yeah, sorry, i kind of assumed “command doesnt work” would result in the hook failing … indeed that doesnt need to be the case …

@aschaepper makes sure to use “set -e”, that will make the hook exit nonzero if a command in it failed (though in case of gadgets that also means the gadget wont get installed … which in turn will drag a bunch of other failures behind it)

I tried it like you said:

I put set -e in the pre-refresh hook, and I put in a a silly command that does not exist. “abc” which will result in a “command not found” error.

Then i listed the changes with:
$ snap changes

gave me the change number, and then I did:
$ snap tasks myschangenumber

As you warned this locked now my snap from beeing uninstalled because the hook fails.
And now I see exactly only the command which failed, which is ok.

But still I’m kind of far away what I would expect:

I would like to have a solution like in CI/CD pipelines or other Toolchains / Environments where I can just view the log.

In Jenkins for example I always get the “build” log, where I can see what it does. If I do the set +x and set -x thing I would also see which commands did actually fire (even with more detail than normal).

Becuase in my case, when doing pre-refresh stuff, you can get kind of “weird” output because this script seems to fire twice and if you would have errors in the first call but no errors in the second call and vise versa the output would look “random”.

So a log like in jenkins where you see which command did run and which did cause errors would be great…

But as from judging your responses its simply not possible to have this for the hooks.

Anyway, thanks a lot for your help!