4

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 Mar 4 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 at 10:49
  • do you want an animated GIF( en.wikipedia.org/wiki/GIF )? – user2497 Mar 4 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 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 at 16:57
4

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 at 14:20
  • How does this visualize the execution of a script? – Ingo Mar 4 at 16:38
  • View the log.txt file or repeatedly 'tail log.txt' – CoderMike Mar 4 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 at 16:50
  • My understanding is too view the output of the scripts - usually when something is not working. – CoderMike Mar 4 at 16:51
1

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:

#!/bin/bash

exec {varFD}>/home/pi/yourScript.log
BASH_XTRACEFD=$varFD

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
+ CAMERALOCATION='Office Door'
++ 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}'
+ CAMERAIPV4=192.168.1.22
++ cut -d / -f1
++ grep -P '^(?!fe80)[[:alnum:]]{4}:.*/64'
++ awk '{print $2}'
++ ip -6 addr
+ CAMERAIPV6=
+ msmtp joe.bloggs@gmail.com
++ echo 192.168.1.22
++ hostname
+ echo -e 'Subject: IP of Camera: 192.168.1.22\r\n\r\nIP Address of Office Door Camera pi3Bplus-camera1.example.com is: 192.168.1.22 /  '\''\n'\'' Script sending this email: /home/pi/open-ipcamera-scripts/email-camera-address.sh'

HTH-

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.