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-
screen
ortmux
and run command inside it or put printed dats to the file using>
. – Matej Mar 04 '19 at 10:49