#!/usr/bin/env sh cd /media/floppy/cip400/ log_file="/var/log/cip400.txt" process_ids="" trap 'terminate' INT TERM venv=".venv" if [ ! -d "$venv" ]; then echo "No venv dir. Creating it now..." python3 -m venv .venv source .venv/bin/activate pip install pyModbusTCP deactivate fi source .venv/bin/activate terminate() { for pid in $process_ids; do echo "terminating process $pid" >> $log_file kill $pid done exit 1 } for i in $(seq 11800 11829); do echo "starting CIP400 at port $i" >> $log_file python3 cip400.py --host '0.0.0.0' --port $i --daemon & process_ids="$process_ids $!" done echo $process_ids >> $log_file wait echo 'that is it' >> $log_file exit 0 # cp /media/floppy/cip400/cip400 /etc/init.d/ # chmod 744 /etc/init.d/cip400 # rc-update add cip400 default # service cip400 status