Hi all,
See my following codes:
------------------------------------------------
# extract two fields from the csv list file -- a name and
# a base64 encoded config file, save each of the contained config
# files as plain text in a file
curl --max-time $curl_max_time_csv
http://130.158.6.81/api/iphone/ |
awk -F $'\r|,' -v ts=$( date +%s ) '/^vpn/ { printf "%s", $(NF-1) |
"base64 -d > ."$1"_"$7"_"ts }'
# mimic the ``sed -i'' to replace the job done by dos2unix:
awk -i inplace '{ sub(/\r$/,""); print }' .vpn*
# renanme each config file using specific values
# from the respective config files
awk '
/^remote / { ip = $2; port = $3 }
/^proto / { proto = $2 }
ENDFILE {
# only keep the config files for servers which support tcp protocol,
# and the corresponding config file hasn't been retrieved till now:
delete a; split(FILENAME,a,"_")
if (proto == "tcp" && system( "[ $( find . -type f -regextype posix-
extended -regex .*/vpngate_"ip"_"proto"_"port".ovpn_"a[length(a)-1]"_[1-9]
[0-9]*$ | wc -l ) -eq 0 ]" ) == 0)
system( "mv "FILENAME" vpngate_"ip"_"proto"_"port".ovpn_"a[length
(a)-1]"_"a[length(a)] )
else
system( "rm "FILENAME )
}' .vpn*
------------------------------------------------
In my above codes, I use a system() function to execute complex shell
commands within awk's code. It seems ugly though it works. I want to
simplify the code with in system().
Any notes/hints?
Regards
--
.: Hongyi Zhao [ hongyi.zhao AT
gmail.com ] Free as in Freedom :.