#!/bin/bash file=`arp` file_name=`arp | awk '{print $1}'` #echo "the file_name is $file_name" file_iface=`cat showportmacs | awk '{print $1}'` name_array="" a=1 for num in $file_name do #echo "the ip is $num" arp_mac=`arp | awk 'NR=='"$a"'{print $3}'` echo "arp_mac is $arp_mac" arp_ip=`arp | awk 'NR=='"$a"'{print $1}'` echo "arp_ip is $arp_ip" #name_array=$name a=$(($a+1)) #echo "the a is $name" j=0 for iface in $file_iface do brl_iface=`cat showportmacs | awk 'NR=='"$j"'{print $1}'` brl_mac=`cat showportmacs | awk 'NR=='"$j"'{print $2}'` brl_flag=`cat showportmacs | awk 'NR=='"$j"'{print $3}'` #echo "the brl iface:$brl_iface ; brl_mac:$brl_mac ; brl_flag:$brl_flag" if [ "${brl_flag}" == "no" ]; then echo "this is no brl_iface:$brl_iface ; brl_mac:$brl_mac" if [ $arp_mac == $brl_mac ]; then echo "the is right" fi fi j=$(($j+1)) done done echo "name $name_array"
file_name=`cat /proc/net/arp` num_name=`echo "$file_name" | awk '{print $1}'` #echo "the num_name is $num_name" #echo "the file_name is $file_name" file_iface=`brctl showportmacs br0` num_iface=`echo "$file_iface" | awk '{print $1}'` name_array="" flag="no" #echo "the flag is &flag" a=1 number=1 for num in $num_name do #echo "the ip is $num" arp_mac=`echo "$file_name" | awk 'NR=='"$a"'{print $4}'` #arp_mac=`cat /proc/net/arp | awk 'NR=='"$a"'{print $4}'` #arp_mac=`arp | awk 'NR=='"$a"'{print $3}'` #echo "arp_mac is $arp_mac" arp_ip=`echo "$file_name" | awk 'NR=='"$a"'{print $1}'` #arp_ip=`cat /proc/net/arp | awk 'NR=='"$a"'{print $1}'` #arp_ip=`arp | awk 'NR=='"$a"'{print $1}'` #echo "the a is $a" #echo "arp_ip : $arp_ip and arp_amc : $arp_mac" #name_array=$name a=`expr $a + 1` #echo "the a is $a" j=1 for iface in $num_iface do brl_iface=`echo "$file_iface" | awk 'NR=='"$j"'{print $1}'` brl_mac=`echo "$file_iface" | awk 'NR=='"$j"'{print $2}'` brl_flag=`echo "$file_iface" | awk 'NR=='"$j"'{print $3}'` #brl_iface=`brctl showportmacs br0 | awk 'NR=='"$j"'{print $1}'` #brl_mac=`brctl showportmacs br0 | awk 'NR=='"$j"'{print $2}'` #brl_flag=`brctl showportmacs br0 | awk 'NR=='"$j"'{print $3}'` #echo "the brl iface:$brl_iface ; brl_mac:$brl_mac ; brl_flag:$brl_flag" if [ "$brl_iface" = "ra0" ] || [ "$brl_iface" = "rai0" ]; then if [ "$brl_flag" = "$flag" ]; then #echo "this is arp_mac:$arp_mac ; brl_mac:$brl_mac" if [ "$arp_mac" = "$brl_mac" ]; then #echo "the is right" echo "<tr> <TD ><STRONG>$number</STRONG></TD> <TD ><STRONG>$brl_iface</STRONG></TD> <td ><strong>$arp_ip</strong></td> <td><strong>$arp_mac</strong></td> <td><strong>$channel</strong></td> </tr>" number=`expr $number + 1` #echo "$brl_iface" >>/tmp/mac_tmp #echo "$arp_ip" >>/tmp/mac_tmp #echo "$arp_mac" >>/tmp/mac_tmp fi fi fi j=`expr $j + 1` done done
没有最新的bash很多处理都想吐血
#第三版 file_name=`cat /proc/net/arp` num_name=`echo "$file_name" | awk '{print $1}'` #echo "the num_name is $num_name" #echo "the file_name is $file_name" file_iface=`brctl showportmacs br0` num_iface=`echo "$file_iface" | awk '{print $1}'` name_array="" flag="no" #echo "the flag is &flag" a=1 number=1 for num in $num_name do #echo "the ip is $num" arp_mac=`echo "$file_name" | awk 'NR=='"$a"'{print $4}'` #arp_mac=`cat /proc/net/arp | awk 'NR=='"$a"'{print $4}'` #arp_mac=`arp | awk 'NR=='"$a"'{print $3}'` #echo "arp_mac is $arp_mac" arp_ip=`echo "$file_name" | awk 'NR=='"$a"'{print $1}'` #arp_ip=`cat /proc/net/arp | awk 'NR=='"$a"'{print $1}'` #arp_ip=`arp | awk 'NR=='"$a"'{print $1}'` #echo "the a is $a" #echo "arp_ip : $arp_ip and arp_amc : $arp_mac" #name_array=$name a=`expr $a + 1` #echo "the a is $a" j=1 for iface in $num_iface do brl_iface=`echo "$file_iface" | awk 'NR=='"$j"'{print $1}'` brl_mac=`echo "$file_iface" | awk 'NR=='"$j"'{print $2}'` brl_flag=`echo "$file_iface" | awk 'NR=='"$j"'{print $3}'` #brl_iface=`brctl showportmacs br0 | awk 'NR=='"$j"'{print $1}'` #brl_mac=`brctl showportmacs br0 | awk 'NR=='"$j"'{print $2}'` #brl_flag=`brctl showportmacs br0 | awk 'NR=='"$j"'{print $3}'` #echo "the brl iface:$brl_iface ; brl_mac:$brl_mac ; brl_flag:$brl_flag" if [ "$brl_iface" = "ra0" ] || [ "$brl_iface" = "rai0" ]; then if [ "$brl_flag" = "$flag" ]; then #echo "this is arp_mac:$arp_mac ; brl_mac:$brl_mac" if [ "$arp_mac" = "$brl_mac" ]; then #echo "the is right" echo "<tr> <TD ><STRONG>$number</STRONG></TD> <TD ><STRONG>$brl_iface</STRONG></TD> <td ><strong>$arp_ip</strong></td> <td><strong>$arp_mac</strong></td>" if [ "$brl_iface" = "rai0" ]; then echo "<td><strong>$rai0_channel</strong></td> <td><strong>$rai0_mode</strong></td>" else echo "<td><strong>$ra0_channel</strong></td> <td><strong>$ra0_mode</strong></td>" fi echo "</tr>" number=`expr $number + 1` #echo "$brl_iface" >>/tmp/mac_tmp #echo "$arp_ip" >>/tmp/mac_tmp #echo "$arp_mac" >>/tmp/mac_tmp fi fi fi j=`expr $j + 1` done done
cgi文档总结
1、cgi中执行shell脚本echo命令,能够将打印输出到相对应调用cgi的页面中去,同时也能够将输出重定向到后台的指定文件中去
但是目前没有打印到后台终端的经验,使用>/dev/console也一样无法输出到后台终端
2、awk的使用 file_name=`arp | awk 'NR==1{print $2}'`
3、shell中变量的自增
a=`expr $a + 1`
4、shell中比较两个字符串的方式
if [ "$a" = "$b"]
添加逻辑运算符是在方括号添加
if [ "$b" = "$a" ] || [ "$str1" = "$str"]