feature: automatic path name in sharter.sh

This commit is contained in:
Uwe Hennig 2023-05-15 08:26:55 +02:00
parent 940da180e6
commit 9855095294

View file

@ -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"