ak835
1
bash-3.00$ /usr/bin/netstat -an -f inet | awk -F' ' '{if ($1$4 == "tcp*.21")print $5}'
*.*
bash-3.00$ A=` /usr/bin/netstat -an -f inet | awk -F' ' '{if ($1$4 == "tcp*.21")print $5}'`
bash-3.00$ echo $A
db2_lastdone.bkp
As you can see ,after running command i get *.* in return but the same command if try to assign it to a variable ,i get something else.
How do i assign "*.*" to a variable?
Note :'db2_lastdone.bkp' is a file present in the location where i am running this command.
Regards
Abhi
I thnk you are getting *.* in the variable, when you try to echo it the shell expands it to a listing of the contents of the directory you are in.
I do your command on bash and it's works fine...
var=$(netstat -an -f inet | awk -F' ' '{if ($1$4 == "tcp4*.21")print $5}');echo $var
*.*
ak835
4
well....its not working for me !!
any other way of assigning *.* to a variable?
Can 'sed' be used ?
Regards
Abhi
Scott
5
$ A=$(/usr/bin/netstat -an -f inet | awk -F' ' '{if ($1$4 == "tcp*.21")print $5}')
$ echo "$A"
*.*
Or if you're desperate:
set -o noglob
echo $A
*.*
ak835
6
well...i am putting here what i am trying to achieve...
Family: Host NWStats
DUP:
/usr/bin/netstat -an -f inet |egrep -v "Active|Proto"|awk '{print $1$4}'
Protocol:
A=$(/usr/bin/netstat -an -f inet | awk -F' ' '{if ($1$4 == "@@Host NWStats.DUP@@" ) print $1}')
B=$(echo "$A"|cut -c 1-3)
echo "$B"
Local IP:
A=$(/usr/bin/netstat -an -f inet | awk -F' ' '{if ($1$4 == "@@Host NWStats.DUP@@" ) print $4}')
B=$(echo "$A"|grep "*"|wc -l)
if [ "$B" = 1 ]
then
C=$(echo "$A"|cut -d "." -f1)
echo "$C"
fi
if [ "$B" = 0 ]
then
D=$(echo "$A"|cut -d "." -f1-4)
echo "$D"
fi
For first column Protocol ,i am not getting values as seen when the command is fired...
For Local IP,i am not getting anything...just blanks...
Any guesses? Anything wrong in above lines ? Any better ideas?
Help Appreciated !!
Regards
Abhi
---------- Post updated 10-29-09 at 05:33 PM ---------- Previous update was 10-28-09 at 09:35 PM ----------
Okay..i got where i wrote wrong.... but this code is just tested on AIX hosts .I need to test this on Solaris as well as Linux hosts.
I'll keep posted.
Regards
Abhi
Family: Host NWStats
DUP:
/usr/bin/netstat -an -f inet |egrep -v "Active|Proto"|awk '{print $1$4$5}'
Protocol:
A=$(/usr/bin/netstat -an -f inet | awk -F' ' '{if ($1$4$5 == "@@Host NWStats.DUP@@" ) print $1}')
B=$(echo "$A"|cut -c 1-3)
echo "$B"
Local IP:
A=$(/usr/bin/netstat -an -f inet | awk -F' ' '{if ($1$4$5 == "@@Host NWStats.DUP@@" ) print $4}')
B=$(echo "$A"|grep "*"|wc -l)
if [ $B = 1 ]
then
C=$(echo "$A"|cut -d "." -f1)
echo "$C"
fi
if [ $B = 0 ]
then
D=$(echo "$A"|cut -d "." -f1-4)
echo "$D"
fi