New version of configuration and control script
This commit is contained in:
parent
35f9b0b644
commit
91f7ea8f5f
2 changed files with 58 additions and 0 deletions
41
moxanix2.sh
Executable file
41
moxanix2.sh
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
#!/bin/bash
|
||||
|
||||
CONFIGURATION_FILE="moxanix2.cfg"
|
||||
|
||||
LINES=()
|
||||
CONNECTIONS=()
|
||||
SIZE=0
|
||||
ARGUMENTS=()
|
||||
|
||||
read_config()
|
||||
{
|
||||
# read lines from the configuration file
|
||||
readarray LINES < $CONFIGURATION_FILE
|
||||
|
||||
# count the number of configured connections and extract arguments
|
||||
# while skipping comment lines and empty lines
|
||||
count=0
|
||||
while [ "${LINES[count]}" != "" ]
|
||||
do
|
||||
LINE=${LINES[count]}
|
||||
# filter lines and arguments according to the configuration format:
|
||||
# tcp=<tcp_port> tty=<tty_device> baud=<tty_baudrate>
|
||||
LINE_VALID=$(echo $LINE | grep -E "^tcp=")
|
||||
if [ -n "$LINE_VALID" ]; then
|
||||
CONNECTIONS[SIZE]=$LINE
|
||||
TCP=$(echo $LINE | awk '{print $1}' | tr -d "tcp=")
|
||||
TTY=$(echo $LINE | awk '{print $2}' | tr -d "tty=")
|
||||
BAUD=$(echo $LINE | awk '{print $3}' | tr -d "baud=")
|
||||
ARGUMENTS[SIZE]="-p $TCP -t $TTY -b $BAUD"
|
||||
# increment size counter
|
||||
SIZE=$(( $SIZE + 1 ))
|
||||
fi
|
||||
# increment line counter
|
||||
count=$(( $count + 1 ))
|
||||
done
|
||||
}
|
||||
|
||||
read_config
|
||||
echo "size is $SIZE"
|
||||
echo ${CONNECTIONS[3]}
|
||||
echo ${ARGUMENTS[3]}
|
||||
Loading…
Add table
Add a link
Reference in a new issue