-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpushConfig.sh
37 lines (33 loc) · 1.08 KB
/
pushConfig.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
#haim.lichaa 2021 initial
CONFIGFILE=device.config
FILE=$1
RUN=$2
if [ -z $FILE ] || [ ! -f $FILE ];then
echo "Usage: $0 <FILE> -f"
echo "FILE in getKeys format,skips first line"
echo "-f force run, otherwise will dry run to stdout"
exit 1
fi
cat $FILE|tail -n +2|while read line;do
APPID=$(echo $line|cut -f4 -d";")
DEVEUI=$(echo $line|cut -f2 -d";")
MODEL=$(echo $line|cut -f9 -d";"|jq -r ".Model")
CONFIGS=`grep -v ^# $CONFIGFILE|grep "^$APPID,.*,$MODEL,.*" |cut -f5 -d","`
FPORT=`grep -v ^# $CONFIGFILE|grep "^$APPID,.*,$MODEL,.*" |tail -n 1| cut -f4 -d","`
if [ -z "$CONFIGS" ];then
echo "NO configs found for appId=[$APPID] with model=[$MODEL]"
continue
fi
echo "Found $CONFIGS for $APPID"
for config in $CONFIGS;do
out="mosquitto_pub -h $MQTTBROKER -p $MQTTPORT -t 'application/'$APPID'/device/'$DEVEUI'/command/down' -m '{\"confirmed\": true, \"fPort\": $FPORT, \"data\": \"'$config'\" }'"
if [ ! -z $RUN ];then
echo "Sending $CONFIG to $DEVEUI"
bash -c "$out"
else
echo $out
fi
sleep 0.2
done
done