This commit is contained in:
parent
dd822625d6
commit
c7bb0b9df9
|
@ -1 +1 @@
|
||||||
mySimpleLog_*
|
mySimpleLog*
|
|
@ -2,24 +2,18 @@
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
# clean data and filter some to rediect to new file
|
# clean data and filter some to rediect to new file
|
||||||
|
# env: rlx linux with origin-awk
|
||||||
# Author: Liao
|
# Author: Liao
|
||||||
# modify time: 2022/2/17 17:05 (+8:00)
|
# modify time: 2022/2/18 16:05 (+8:00)
|
||||||
#############################
|
#############################
|
||||||
|
|
||||||
BEGIN{
|
BEGIN{
|
||||||
fileSize = 1024*1
|
fileSize = 1024*1
|
||||||
|
uploadCount = 0
|
||||||
|
|
||||||
# filePath = "/data/log_dir/mySimpleLog"
|
# filePath = "/data/log_dir/mySimpleLog"
|
||||||
|
|
||||||
# system("echo '\n\n\n----------' >> "awk_run_log_path" && date '+%x %X' >> "awk_run_log_path)
|
log2file("{ \"event\":\"gateway startup\"}")
|
||||||
|
|
||||||
#dp_recv_from_device = @/ dp rept_type:[0-9]+, data:/
|
|
||||||
#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\"}")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,14 +27,14 @@ $0~/ dp rept_type:[0-9]+, data:/ {
|
||||||
|
|
||||||
$0~/rev id:\w+ cmd:\{.*\} type:0/ {
|
$0~/rev id:\w+ cmd:\{.*\} type:0/ {
|
||||||
atime = match($0,/[0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3}/) ? substr($0,RSTART,RLENGTH) : null;
|
atime = match($0,/[0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3}/) ? substr($0,RSTART,RLENGTH) : null;
|
||||||
adps = match($0,/cmd:\{.+\} /) ? substr(substr($0,RSTART,RLENGTH),5,RLENGTH-5) : "unkown";
|
adps = match($0,/cmd:\{.+\} /) ? substr(substr($0,RSTART,RLENGTH),5,RLENGTH-5) : "\"unkown\"";
|
||||||
devMac = match($0,/rev id:\w+/) ? substr(substr($0,RSTART,RLENGTH),8) : null
|
devMac = match($0,/rev id:\w+/) ? substr(substr($0,RSTART,RLENGTH),8) : null
|
||||||
|
|
||||||
if((getline conditionLine) > 0){
|
if((getline conditionLine) > 0){
|
||||||
isCondition = match(conditionLine,/(no id match|no dp match)/) ? "false" : match(conditionLine,/dp [0-9]+ match/) ? "true" : "unkown"
|
isCondition = match(conditionLine,/(no id match|no dp match)/) ? "false" : match(conditionLine,/dp [0-9]+ match/) ? "true" : "\"unkown\""
|
||||||
condition = "\"isCondition\":"isCondition
|
condition = "\"isCondition\":"isCondition
|
||||||
if (isCondition=="true"){
|
if (isCondition=="true"){
|
||||||
conditionDp = match(conditionLine,/\] dp [0-9]+ match/) ? substr(substr(conditionLine,RSTART,RLENGTH),6,RLENGTH-11) : "unkown"
|
conditionDp = match(conditionLine,/\] dp [0-9]+ match/) ? substr(substr(conditionLine,RSTART,RLENGTH),6,RLENGTH-11) : "\"unkown\""
|
||||||
condition = condition",\"conditionDp\":"conditionDp
|
condition = condition",\"conditionDp\":"conditionDp
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
@ -55,12 +49,12 @@ $0~/condition set is ok,then execute action set\./ {
|
||||||
# print $0
|
# print $0
|
||||||
atime = match($0,/[0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3}/) ? substr($0,RSTART,RLENGTH) : null;
|
atime = match($0,/[0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3}/) ? substr($0,RSTART,RLENGTH) : null;
|
||||||
aruleid = match($0,/scene:\w+,/) ? substr(substr($0,RSTART,RLENGTH),7,RLENGTH-7) : "false"
|
aruleid = match($0,/scene:\w+,/) ? substr(substr($0,RSTART,RLENGTH),7,RLENGTH-7) : "false"
|
||||||
log2file("{ \"time\":"atime", \"event\":\"trigger\", \"ruleid\":\""aruleid"\",\"triggerNow\":\"true\"}")
|
log2file("{ \"time\":"atime", \"event\":\"trigger\", \"ruleid\":\""aruleid"\",\"triggerNow\":true}")
|
||||||
}
|
}
|
||||||
|
|
||||||
$0~/action<[0-9]+> is dp cmd:/ {
|
$0~/action<[0-9]+> is dp cmd:/ {
|
||||||
atime = match($0,/[0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3}/) ? substr($0,RSTART,RLENGTH) : null;
|
atime = match($0,/[0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3}/) ? substr($0,RSTART,RLENGTH) : null;
|
||||||
adps = match($0,/cmd:\{.+\}$/) ? substr(substr($0,RSTART,RLENGTH),5,RLENGTH-4) : "unkown";
|
adps = match($0,/cmd:\{\".+\}/) ? substr(substr($0,RSTART,RLENGTH),5,RLENGTH-4) : ""$0;
|
||||||
|
|
||||||
aLogJson = "{ \"time\":"atime", \"event\":\"action\", \"cmd\":"adps"}"
|
aLogJson = "{ \"time\":"atime", \"event\":\"action\", \"cmd\":"adps"}"
|
||||||
log2file(aLogJson)
|
log2file(aLogJson)
|
||||||
|
@ -68,16 +62,8 @@ $0~/action<[0-9]+> is dp cmd:/ {
|
||||||
|
|
||||||
|
|
||||||
END{
|
END{
|
||||||
|
splitAndUpload()
|
||||||
}
|
print "upload "uploadCount" count"
|
||||||
|
|
||||||
function matchRet(reg ,RSTART,RLENGTH){
|
|
||||||
#print reg
|
|
||||||
if(match($0,$reg)){
|
|
||||||
return substr($0,RSTART,RLENGTH)
|
|
||||||
}else{
|
|
||||||
return "Nothing Matched"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function log2file(logJson){
|
function log2file(logJson){
|
||||||
|
@ -85,21 +71,19 @@ function log2file(logJson){
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkFileSize(){
|
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} }'")
|
checkState = system("ls -l /data/log_dir/mySimpleLog | awk '{ if($5 >"fileSize"){exit 0}else{exit 1} }'")
|
||||||
print checkState
|
|
||||||
if(!checkState){
|
if(!checkState){
|
||||||
print "uploading..."
|
|
||||||
splitAndUpload()
|
splitAndUpload()
|
||||||
# print "uploaded"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function splitAndUpload(){
|
function splitAndUpload(){
|
||||||
newFileName = "mySimpleLog_"systime()
|
newFileName = "mySimpleLog_"systime()
|
||||||
|
print "uploading..."
|
||||||
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)
|
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){
|
if(!ret){
|
||||||
print "upload success!"
|
print "upload success!"
|
||||||
|
uploadCount++
|
||||||
}else{
|
}else{
|
||||||
print "upload fail!"
|
print "upload fail!"
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,4 @@
|
||||||
|
|
||||||
cd /tmp && tftp 192.168.1.5 -g -l logDataClean.awk
|
cd /tmp && tftp 192.168.1.5 -g -l logDataClean.awk
|
||||||
|
|
||||||
tail -f /tmp/tuya.log | awk -f logDataClean.awk &
|
tail -f /tmp/tuya.log | awk -f logDataClean.awk > /dev/null &
|
Binary file not shown.
Loading…
Reference in New Issue