cgi处理shell

#!/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"]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

潘多拉的面

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值