I have a script that always runs on the Raspberry Pi.

I defined with sudo nano /etc/rc.local so that they turn even after a reboot or a power failure.

My question is how can visualize the execution of my scrpits after rebooting or power failure especially that there are "print" (because the execution becomes in the background).

  • You might be looking for Bootchart. See e.g. the answers to this question: raspberrypi.stackexchange.com/questions/78099/… – Piskvor left the building Mar 4 '19 at 10:45
  • Do you want to catch prited data? If yes, you can use screen or tmux and run command inside it or put printed dats to the file using >. – Matej Mar 4 '19 at 10:49
  • do you want an animated GIF( en.wikipedia.org/wiki/GIF )? – user2497 Mar 4 '19 at 14:49
  • How do you want the visualization to appear? On the command line, in a graphical GUI, a LED connected to a GPIO or a web page ? – MatsK Mar 5 '19 at 13:24
  • The swirling dash is a godlike version of progress meters. All you need is a shell, ‘/‘, ‘\’, and 0x0d controlchar. Other versions exist (on my system at least), in which ascii drawings of mammal genitalia (so it’s not necessary to remove my comment, over-zealous moderators!) is animated to give the impression that progress is made. – user2497 Mar 5 '19 at 16:57

Redirect output and errors to a file:

myscript.sh >> /home/pi/log.txt 2>&1 &
  • Mind the last &, it sends the script execution to the background (you may don't want to). – GramThanos Mar 4 '19 at 14:20
  • How does this visualize the execution of a script? – Ingo Mar 4 '19 at 16:38
  • View the log.txt file or repeatedly 'tail log.txt' – CoderMike Mar 4 '19 at 16:41
  • What is your understanding of visualize? Looking at scrolling text? For me it's unclear what the OP means. Is it a bootchart, catching printed data or an animated gif, as others already asked? – Ingo Mar 4 '19 at 16:50
  • My understanding is too view the output of the scripts - usually when something is not working. – CoderMike Mar 4 '19 at 16:51

Redirect output of set -x to a log to capture any potential errors as script executed.

varFD is an arbitrary variable name (you could call it something else if you wish) and used here to assign the next unused File Descriptor to redirect output to the log

In your script under the SheBang add the following:


exec {varFD}>/home/pi/yourScript.log

set -x

This will give you granular feedback on how the script operated, including how variables DID, or worse, DID NOT expand. Specimen output from one of my scripts from the log where it was captured:

+ sleep 10
++ readlink -f /home/pi/open-ipcamera-scripts/email-camera-address.sh
+ SCRIPTLOCATION=/home/pi/open-ipcamera-scripts/email-camera-address.sh
++ sudo sed -n 's/sysLocation.[[:space:]]*//p' /etc/snmp/snmpd.conf
++ sudo sed -n 's/sysContact.[[:space:]]*//p' /etc/snmp/snmpd.conf
+ SYSCONTACT=joe.blogs@gmail.com
++ ip addr list
++ grep inet
++ awk FNR==2
++ grep -oE '[1-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
++ cut -d / -f1
++ grep -P '^(?!fe80)[[:alnum:]]{4}:.*/64'
++ awk '{print $2}'
++ ip -6 addr
+ msmtp joe.bloggs@gmail.com
++ echo
++ hostname
+ echo -e 'Subject: IP of Camera:\r\n\r\nIP Address of Office Door Camera pi3Bplus-camera1.example.com is: /  '\''\n'\'' Script sending this email: /home/pi/open-ipcamera-scripts/email-camera-address.sh'


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.