我正在用 Bash 编写脚本。下面的输出是错误的。我提取的测试数据使得所有允许和拒绝的连接都应该在时间“00”内,但我每天浏览时,它都会跳到下一个小时。下面是我的代码,最底部是示例输出。你能帮我吗?这让我很头疼。
#!/bin/bash
echo "MEGA CRAWLER BY DA INTERNS" > Result
echo "Enter the month of the file you're trying to read"
echo "If month is one number enter one number if two numbers enter two numbers"
read M
#case staement changes M input into a month an reassigns single digit months into double digit
if [[ $M -lt 13 && $M -gt 0 ]]
then
case "$M" in
"1") month="Jan" ; M="01" ; Dlim="31"
;;
"2") month="Feb" ; M="02" ; Dlim="29"
;;
"3") month="Mar" ; M="03" ; Dlim="31"
;;
"4") month="Apr" ; M="04" ; Dlim="30"
;;
"5") month="May" ; M="05" ; Dlim="31"
;;
"6") month="Jun" ; M="06" ; Dlim="30"
;;
"7") month="Jul" ; M="07" ; Dlim="31"
;;
"8") month="Aug" ; M="08" ; Dlim="31"
;;
"9") month="Sep" ; M="09" ; Dlim="30"
;;
"10") month="Oct" ; Dlim="31"
;;
"11") month="Nov" ; Dlim="30"
;;
"12") month="Dec" ; Dlim="31"
;;
esac
else
echo "Please make sure to enter a valid month."
read M
fi
echo -e ""
echo "Enter the year of the file you're trying to read"
read Y
echo -e ""
for D in $(seq -f "%02g" 1 5); do
File=($(find -name "traffic_$M-$D-$Y"))
echo "-------------------------DAY $D-------------------------" >> Result
for i in $(seq -f "%02g" 0 23); do
grep "$month $i" $File > TempOutput
countAllow=($(grep -c "allow" TempOutput))
countDeny=($(grep -c "deny" TempOutput))
echo -e "$countAllow connections allowed at $i time" >> Result
echo -e "$countDeny connections denied at $i time\n" >> Result
rm TempOutput
done
done
-------------------------DAY 01-------------------------
0 connections allowed at 00 time
0 connections denied at 00 time
77 connections allowed at 01 time
25 connections denied at 01 time
0 connections allowed at 02 time
0 connections denied at 02 time
-------------------------DAY 02-------------------------
0 connections allowed at 00 time
0 connections denied at 00 time
0 connections allowed at 01 time
0 connections denied at 01 time
76 connections allowed at 02 time
26 connections denied at 02 time