Tips for debugging scripts

How can I see the output of my command to run?

We are currently developing a full feedback loop gathering all information from the output of our command to run or any script and feed it back into the qbee UI. Until then we can show you a work around to get some more insight into what is happening on the device.

It is recommended to catch all output from a "command to run" and pipe it to > /dev/null 2>&1 &. This effectively suppresses any output. It helps qbee to not wait for this output, but this can leave you blind while building your scripts. Therefore, a natural debugging possibility is to pipe this into log file like this

    sudo -u pi bash /path/to/my/script.sh > /path/to/output/output.log

This works very well, but even though we run the script in the "pi" user context the output will belong to root. This can be changed by using a slightly different command utilizing tee.

    sudo -u pi bash /path/to/my/script.sh | sudo -u pi tee /path/to/output/output.txt

Now the output also belongs to user "pi".

How do I produce log files with the correct user context?

Running your script in the user context as described above will cause the output written by the program to be written for that user. However, when piping to a text file the owner will be root as the process is still by qbee in the root context. A way to circumvent this issue is to use the tee command as follows:

sudo -u pi bash /path/to/my/script.sh | sudo -u pi tee /path/to/output/output.txt

whereas a simple

sudo -u pi bash /path/to/my/script.sh > /path/to/output/output.txt

will result in output.txt being written for root.