- 论坛徽章:
- 145
|
回复 1# bikkuri
There is the sample code for your reference
Note: you have to modify and add more code for warnings ...
$ cat /tmp/enb/enbbase.xml
<?xml version="1.0"?>
<ENBProfile xmlns="https://www.huawei.com/LTE/ENB/profile/v1">
<name>${ENB_NAME}</name>
<IDConfig>
<ID>
<hex>${ENB_HEX}</hex>
<name>${ENB_BASE}</name>
</ID>
</IDConfig>
<Location>${ENB_LOC}</Location>
<ACL>
<security>
<Account>
<User>${ENB_USER}</User>
<Password>${ENB_PASS}</Password>
</Account>
<AuthorizedIP>${ENB_IP}</AuthorizedIP>
</security>
</ACL>
</ENBProfile>
$ cat /tmp/enb/enb.lst
64648 enb43535@shanghai enbadmin 43535Admin# 135.240.144.53
64649 enb24042@shanghai enbadmin 24042Enb! 135.240.146.162
64650 enb74324@beijing enbadmin Mc10vin!! 135.254.61.160
64651 enb52526@beijing enbadmin Mc10vin!! 135.254.62.160
$ bash select_enb.sh 64650
<?xml version="1.0"?>
<ENBProfile xmlns="https://www.huawei.com/LTE/ENB/profile/v1">
<name>enb74324@beijing</name>
<IDConfig>
<ID>
<hex>656e623734333234</hex>
<name>enb74324</name>
</ID>
</IDConfig>
<Location>beijing</Location>
<ACL>
<security>
<Account>
<User>enbadmin</User>
<Password>Mc10vin!!</Password>
</Account>
<AuthorizedIP>135.254.61.160</AuthorizedIP>
</security>
</ACL>
</ENBProfile>
$ cat select_enb.sh
select_enb(){
ENB_PATH="/tmp/enb/"
ENB_FILE="$ENB_PATH/enbbase.xml"
ENB_LIST="$ENB_PATH/enb.lst"
awk -vt="$1" '
BEGIN{
split("x NAME USER PASS IP",a," ")
for(n=33;n<127;n++)
x[sprintf("%c",n)]=sprintf("%02x",n)
}
FNR==NR{
if(t==$1){
c=NF
for(n=2;n<=c;n++){
b[a[n]] = $n
}
}
next
}
{
s=s$0"\n"
}
END{
split(b["NAME"],N,"@")
b["BASE"]=N[1]
b["LOC"]=N[2]
len=length(N[1])
for(n=1;n<=len;n++)
b["HEX"]=b["HEX"]x[substr(N[1],n,1)]
for(n in b)
v=v"ENB_"n"="b[n]";"
gsub("\"","\\\"",s)
cmd=v"\necho -n \""s"\""
#print cmd
system(cmd)
}
' $ENB_LIST $ENB_FILE
}
select_enb $1 |
|