Hi Radoluv,
Thnks for ur valuable replies
My next tasks are
getting the IP and USERAGENT value from the command line argument
call function isInFua ( which is internally calling some othe functions)
FInally i need the Return value (RET_VALUE) like 3G or Smartphone or WAP or WEB...
I am attaching the code with ur changes
#!/bin/sh
IPWeb=( 10.66.24.1 10.66.24.3 10.66.24.4 10.66.24.23 10.66.24.35 10.66.24.34 10.66.24.36 10.66.24.38 10.66.17.151 10.66.17.152 10.66.17.153 10.66.17.
154 10.66.17.155 10.66.17.156 10.66.17.147 10.66.17.148 10.66.17.149 10.66.17.150 )
IPMobile=( 10.163.118.159 10.163.118.160 10.163.118.161 10.163.118.162 10.163.118.163 10.163.118.164 10.163.118.165 10.163.118.166 10.163.118.167 10.163.118.
168 10.163.118.169 10.163.118.170 10.163.118.171 10.163.118.172 10.66.24.40 10.66.24.17 10.66.24.19 10.66.24.37 10.66.17.131 10.66.17.132 10.66.17.133 10.66.
17.134 10.66.17.135 10.66.17.136 10.66.17.137 10.66.17.138 10.66.17.139 10.66.17.144 10.66.17.145 10.66.17.146 )
if [ ! -e $_ficParam ] # e means file exists
then
echo $_ficParam file is misssing
exit
fi
if [ "$_pat" == "" ]
then
_pat=intermediatePattern.txt
fi
if [ ! -e $_pat ] # e means file exists
then
echo "intermediatePattern.txt file is not accessibile"
fi
echo _pat : $_pat
IDX=0
IDX_SP=0
awk 'END {
while (++n <= i)
printf "tg_a, element %d: %s\n", n, THREEG_ARRAY[n]
while (++m <= j)
printf "sp_a, element %d: %s\n", m, SP_ARRAY[m]
}
{
if (/^3G/)
THREEG_ARRAY[++i] = $1
else
SP_ARRAY[++j] = $0
}' $_pat
SIZE\_THREEG_ARRAY=\`echo $\{\#THREEG_ARRAY[*]\}\`
SIZE\_SP_ARRAY=\`echo $\{\#SP_ARRAY[*]\}\`
ALL_ARGS=$* # argument from command line
IP=`echo $ALL_ARGS | awk '{print $1}'` # getting value for IP address
USER_AGENT=$(echo $ALL_ARGS | cut -d'"' -f6) # getting value for USER AGENT
var=0
RET_VALUE=""
function isInFua
{
echo VAR --- $var
isSmartPhone \# calling function for Smart phone
if [ $var == 1 ]
then
RET_VALUE=SmartPhone
return
fi
isThreeG \# calling function for 3G
if [ $var == 1 ]
then
RET_VALUE=3G
return
fi
isFromWAP \# calling function for WAP
if [ $var == 1 ]
then
RET_VALUE=WAP
return
fi
isFromWEB \# \# calling function for WEB
if [ $var == 1 ]
then
RET_VALUE=WEB
return
fi
}
#------------------------------------------------------------------------------#
# Test 3G and 2.5G on a user-agent functions #
#------------------------------------------------------------------------------#
function isSmartPhone
{
for ((i = 0 ; i < $SIZE_SP_ARRAY ; i++))
do
USER_AGENT_VALUE=`echo $USER_AGENT | grep "${SP_ARRAY[$i]}"`
if [ $? = 0 ]
then
var=1
return
fi
done
}
function isThreeG
{
for ((i = 0 ; i < $SIZE_THREEG_ARRAY ; i++))
do
USER_AGENT_VALUE=`echo $USER_AGENT | grep "${THREEG_ARRAY[$i]}"`
if [ $? = 0 ]
then
var=1
return
fi
done
}
function isFromWAP
{
for ((i = 0 ; i < ${#IPMobile[*]} ; i++))
do
IP_MOBILE_VALUE=`echo $IP | grep "${IPMobile[i]}"`
if [ $? = 0 ]
then
var=1
return
fi
done
}
function isFromWEB
{
for ((i = 0 ; i < ${#IPWeb[*]} ; i++))
do
IP_MOBILE_VALUE=`echo $IP | grep "${IPWeb[i]}"`
if [ $? = 0 ]
then
var=1
return
fi
done
}
isInFua
echo RET_VALUE = $RET_VALUE
Can you please go through with this ??
Thanks for the help...