optimize scripts

This commit is contained in:
idea4good 2021-02-23 16:28:25 +08:00
parent e97484cf9d
commit 755b41e474
2 changed files with 24 additions and 18 deletions

View File

@ -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_*

View File

@ -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\",^