From 755b41e4748703047bd05703a6d8e4a200e04b2c Mon Sep 17 00:00:00 2001 From: idea4good Date: Tue, 23 Feb 2021 16:28:25 +0800 Subject: [PATCH] optimize scripts --- workspace/.sync.sh | 36 +++++++++++++++++++++--------------- workspace/sync_build.bat | 6 +++--- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/workspace/.sync.sh b/workspace/.sync.sh index 76acc82..d1c5a1f 100755 --- a/workspace/.sync.sh +++ b/workspace/.sync.sh @@ -8,22 +8,30 @@ build_time=`date +%Y-%m-%dT%H:%M:%S.000%z` device_info=`uname -s -n -m` #--------------- Geo info ----------------# -curl ipinfo.io > ip_info.txt # get IP info +if [ ! -f "/tmp/ip_info.tmp" ]; then + curl ipinfo.io > /tmp/ip_info.tmp # get IP info +fi -grep city ip_info.txt > ip_city.txt # filter city -sed -i 's/"city"://g' ip_city.txt #remove property name -sed -i 's/"//g' ip_city.txt #remove double quotes -city=`sed 's/,//g' ip_city.txt` #remove comma +if [ ! -f "/tmp/ip_city.tmp" ]; then + grep city /tmp/ip_info.tmp > /tmp/ip_city.tmp # filter city + sed -i 's/"city"://g' /tmp/ip_city.tmp #remove property name + sed -i 's/"//g' /tmp/ip_city.tmp #remove double quotes +fi +city=`sed 's/,//g' /tmp/ip_city.tmp` #remove comma -grep country ip_info.txt > ip_country.txt # filter country -sed -i 's/"country"://g' ip_country.txt #remove property name -sed -i 's/"//g' ip_country.txt #remove double quotes -country=`sed 's/,//g' ip_country.txt` #remove comma +if [ ! -f "/tmp/ip_country.tmp" ]; then + grep country /tmp/ip_info.tmp > /tmp/ip_country.tmp # filter country + sed -i 's/"country"://g' /tmp/ip_country.tmp #remove property name + sed -i 's/"//g' /tmp/ip_country.tmp #remove double quotes +fi +country=`sed 's/,//g' /tmp/ip_country.tmp` #remove comma -grep org ip_info.txt > ip_org.txt # filter org -sed -i 's/"org"://g' ip_org.txt #remove property name -sed -i 's/"//g' ip_org.txt #remove double quotes -org=`sed 's/,//g' ip_org.txt` #remove comma +if [ ! -f "/tmp/ip_org.tmp" ]; then + grep org /tmp/ip_info.tmp > /tmp/ip_org.tmp # filter org + sed -i 's/"org"://g' /tmp/ip_org.tmp #remove property name + sed -i 's/"//g' /tmp/ip_org.tmp #remove double quotes +fi +org=`sed 's/,//g' /tmp/ip_org.tmp` #remove comma curl --include --request POST --header "Content-Type: application/json" --data-binary "[{ \"device_info\" :\"$device_info\", @@ -34,5 +42,3 @@ curl --include --request POST --header "Content-Type: application/json" --data-b \"city\" :\"$city\", \"org\" :\"$org\" }]" $url > /dev/null - -rm ip_* diff --git a/workspace/sync_build.bat b/workspace/sync_build.bat index 03272a9..754e81e 100644 --- a/workspace/sync_build.bat +++ b/workspace/sync_build.bat @@ -45,9 +45,9 @@ if not exist "%tmpPath%ip_org.tmp" ( powershell -Command "(gc %tmpPath%ip_org.tmp) -replace ',' , '' | Out-File -encoding ASCII %tmpPath%ip_org.tmp" ) -set country=<%tmpPath%ip_country.tmp -set city=<%tmpPath%ip_city.tmp -set org=<%tmpPath%ip_org.tmp +set /p country=<%tmpPath%ip_country.tmp +set /p city=<%tmpPath%ip_city.tmp +set /p org=<%tmpPath%ip_org.tmp set raw_data=[{^ \"device_info\" :\"%devie_info%\",^ \"project_info\" :\"%1\",^