diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..462013d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +mySimpleLog_* \ No newline at end of file diff --git a/logDataClean.awk b/logDataClean.awk index 34aa47d..2b1a741 100644 --- a/logDataClean.awk +++ b/logDataClean.awk @@ -7,6 +7,7 @@ ############################# BEGIN{ + fileSize = 1024*1 # filePath = "/data/log_dir/mySimpleLog" # system("echo '\n\n\n----------' >> "awk_run_log_path" && date '+%x %X' >> "awk_run_log_path) @@ -15,7 +16,7 @@ BEGIN{ #dp_is_condition = @/dp [0-9]+ match/ #dp_not_condition = @/no id match/ #pattern = @/([0-9]+-[0-9]+ ([0-9]+:){3}[0-9]+)/ -# + #connection_check_ok = @/condition set is ok,then execute action set./ # Get form OS log2file("{\"event\":\"gateway reboot\"}") @@ -27,6 +28,7 @@ $0~/ dp rept_type:[0-9]+, data:/ { adps = match($0,/\{.+\}/) ? substr($0,RSTART,RLENGTH):null; aLogJson = "{ \"time\":"atime", \"event\":\"dp report\", \"dps\":"adps"}" # log2file(aLogJson) + checkFileSize() } $0~/rev id:\w+ cmd:\{.*\} type:0/ { @@ -82,7 +84,23 @@ function log2file(logJson){ system("echo -e '"logJson"' >> /data/log_dir/mySimpleLog") } +function checkFileSize(){ + # system("ls -l /data/log_dir/mySimpleLog | awk '{ print $5 }' | cat > /tmp/bujueFileSize") + checkState = system("ls -l /data/log_dir/mySimpleLog | awk '{ if($5 >"fileSize"){exit 0}else{exit 1} }'") + print checkState + if(!checkState){ + print "uploading..." + splitAndUpload() + # print "uploaded" + } +} + function splitAndUpload(){ - newFileName = "/data/log_dir/mySimpleLog_"systime() - system("mv /data/log_dir/mySimpleLog "newFileName" && tftp 192.168.1.5 -p -l "newFileName" && rm "newFileName) + newFileName = "mySimpleLog_"systime() + ret = system("mv /data/log_dir/mySimpleLog /data/log_dir/"newFileName" && cd /data/log_dir/ && tftp 192.168.1.5 -p -l "newFileName" && rm "newFileName) + if(!ret){ + print "upload success!" + }else{ + print "upload fail!" + } } \ No newline at end of file diff --git a/start_monitor.sh b/start_monitor.sh index 3adeeb3..2d00b29 100644 --- a/start_monitor.sh +++ b/start_monitor.sh @@ -1,16 +1,6 @@ +# 上位机启动tftp,并将base目录设为项目根目录 +# 远程ssh登录,然后执行以下命令 +cd /tmp && tftp 192.168.1.5 -g -l logDataClean.awk -# 创建场景 -tail -f /tmp/tuya.log | grep '\] Rev MQTT:' | grep '"ruleId":' | awk -f ./logDataClean.awk >> /data/SceneLinkage & - -# 触发场景 -tail -f /tmp/tuya.log | grep 'condition set is ok,then execute action set. scene:' |awk -f >> - -# 子设备上报 -# 是否有相关场景( dp \d+ match | no dp match) -# 条件判断(conditions check finish. result:true) - # 条件判断结果(condition set is ok,then execute action set. scene:6DAMVviZamUqanPP, 0x8b26d8) -# 动作执行(in work-queue. execute scene:6DAMVviZamUqanPP begin)([scene_linkage_rule_exe.c) -# 子设备上报 - - +tail -f /tmp/tuya.log | awk -f logDataClean.awk & \ No newline at end of file