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).

F1Linux
  • 1,667
  • 1
  • 12
  • 30
Amélie
  • 41
  • 1
  • You might be looking for Bootchart. See e.g. the answers to this question: https://raspberrypi.stackexchange.com/questions/78099/how-can-i-lower-my-boot-time-more – Piskvor left the building Mar 04 '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 04 '19 at 10:49
  • do you want an animated GIF( https://en.wikipedia.org/wiki/GIF )? – user2497 Mar 04 '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 05 '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 05 '19 at 16:57

2 Answers2

4

Redirect output and errors to a file:

myscript.sh >> /home/pi/log.txt 2>&1 &
CoderMike
  • 6,982
  • 1
  • 10
  • 15
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-

F1Linux
  • 1,667
  • 1
  • 12
  • 30