From 9855095294227cc798d4808001c53d4e1bb69e71 Mon Sep 17 00:00:00 2001 From: Uwe Hennig Date: Mon, 15 May 2023 08:26:55 +0200 Subject: [PATCH] feature: automatic path name in sharter.sh --- starter.sh | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/starter.sh b/starter.sh index 07273e3..ee38ce4 100755 --- a/starter.sh +++ b/starter.sh @@ -1,5 +1,8 @@ #!/bin/bash +# enter in the pyPLC directory, so that all subsequent pathes can be relative to this. +cd "$( dirname "${BASH_SOURCE[0]}" )" + # Function to start tcpdump start_tcpdump() { INTERFACE="eth0" # Change this to the interface you want to monitor @@ -24,7 +27,7 @@ signal_handler() { # Set trap for signals: SIGINT (2), SIGTERM (15) trap 'signal_handler' 2 15 -# Todo: explain this +# Set options for the bash: exit on error, treat unused variables as error, print the input as it is read. set -euv # Keep all IPv6 addresses on the interface down event. @@ -35,6 +38,7 @@ sysctl net.ipv6.conf.eth0.keep_addr_on_down=1 # Shut down and activate the interface. # Todo: Why this needed? On raspberry, where the NetworkManager is not runnning, this disturbs, because # afterwards the pyPlc does not see the interfaces IPv6 address. +# Todo: make this configurable, for the cases we need this. # ip link set eth0 down sleep 1 # ip link set eth0 up @@ -43,12 +47,15 @@ sleep 1 # show the addresses ip addr -# todo: flexible path name -mkdir -p /home/pi/myprogs/pyPLC/log +# print the current directory to log. Should be the pyPLC directory. +pwd + +# create directory for the log files. +mkdir -p log # prepare the file names for the log files date=$(date "+%Y-%m-%d_%H%M%S") -logfile=/home/pi/myprogs/pyPLC/log/"$date"_pevNoGui.log -tcpdump_logfile=/home/pi/myprogs/pyPLC/log/"$date"_tcpdump.pcap +logfile=./log/"$date"_pevNoGui.log +tcpdump_logfile=./log/"$date"_tcpdump.pcap echo "logfile: $logfile" echo "tcpdump_logfile: $tcpdump_logfile" @@ -60,12 +67,9 @@ echo "$date" >> "$logfile" git log --oneline -1 >> "$logfile" || echo "Not a git repo" >> "$logfile" ip addr >> "$logfile" pwd >> "$logfile" -# Todo: flexible path name -cd /home/pi/myprogs/pyPLC/ -#/usr/bin/python3 /home/user/projects/pyPLC/pevNoGui.py | tee -a "$logfile" -#stdbuf -oL -eL /usr/bin/python3 /home/user/projects/pyPLC/pevNoGui.py | tee -a "$logfile" -#PYTHONUNBUFFERED=1 /usr/bin/python3 /home/user/projects/pyPLC/pevNoGui.py | stdbuf -oL -eL tee -a "$logfile" -PYTHONUNBUFFERED=1 /usr/bin/python3 /home/pi/myprogs/pyPLC/pevNoGui.py | tee -a "$logfile" + +# call the pyPlc python script +PYTHONUNBUFFERED=1 /usr/bin/python3 pevNoGui.py | tee -a "$logfile" pwd >> "$logfile" date >> "$logfile"