本文介绍了probabely"环路QUOT;和"输出"没有在我的bash脚本正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了下面的脚本:
#!/bin/bash
echo "Reading data - headers - both"
if [ $# -ne 3 ]; then
echo "Usage: ./nmap <port-range> <ip-list> <d || h || b>"
exit 1
fi
rm -f /tmp/right.txt 1>/dev/null 2>/dev/null
rm -f /tmp/wrong.txt 1>/dev/null 2>/dev/null
output=""
if [ $3 == h ]; then
while read -r -u3 port; do
while read -r -u4 ip; do
# echo -en "\n$ip $port: "
OUT=$( nmap -p "$port" --script=http-headers.nse "$ip" | awk 'NR>=7 && NR<=10')
# [[ $OUT == *Apache* ]] && $(echo -en "$ip $port\n" >> /tmp/right.txt) || $(echo -en "$ip $port\n" >> /tmp/wrong.txt)
[[ $OUT == *Apache* ]] && output="$output `echo -en "\n$ip -------------------- $port "`" && echo -e "$output" | column -t >> /tmp/right.txt || output="$output `echo -en "\n$ip -------------------- $port "`" && echo -e "$output" | column -t >> /tmp/wrong.txt
done 4< "$2"
done 3< "$1"
echo -e "$output" | column -t
elif [ $3 == d ]; then
echo data
elif [ $3 == b ]; then
echo both
fi
我希望我的输出有两个文件:
I expect my output have two files:
cat right.txt
ip1 ..... port1
ip2 ..... port1
ip2 ..... port2
ip3 ..... port3
.
.
.
cat wrong.txt
ip1 ..... port1
ip2 ..... port1
ip2 ..... port2
ip3 ..... port3
.
.
.
,但它不能正常工作...
but it doesn't work properly...
任何想法?
感谢您提前
推荐答案
请找到更新的答案,因为我修改了宝马的答案请你检查一下。
please find updated answer as i modified the BMW's answer for you please check it.
#!/bin/bash
echo "Reading data - headers - both"
if [ $# -ne 3 ]; then
echo "Usage: ./nmap <port-range> <ip-list> <d || h || b>"
exit 1
fi
join -j 2 $2 $1 > temp.txt
headers()
{
while read -r ip port
do
printf "ip: %s port:%d \n" $ip $port
OUT=$(nmap -p "$port" --script=http-headers.nse "$ip" | tac | awk -F: 'NR<=13&&/Apache/{print $2; exit}')
if [[ "$OUT" == *Apache* ]]; then
echo $ip $port >> /tmp/right.txt
else
echo $ip $port >> /tmp/wrong.txt
fi
done < temp.txt
}
case $3 in
"h") headers ;;
"d") echo data;;
"b") echo both;;
"*") echo "wrong input"
exit;;
esac
这篇关于probabely&QUOT;环路QUOT;和&QUOT;输出&QUOT;没有在我的bash脚本正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!