我有问题要打开while循环并从while循环的开始处开始。我想循环检查连续检查时间是否等于59秒,如果不去while循环检查日志文件。内部while循环只能在日志文件中找到特定的内容时执行某些操作。Break while while循环并转到if/else
编辑:新脚本。问题是,while循环不运行,不回去,在其他环
脚本再次调用该函数的功能:
#!/bin/bash
counterSearch=0
counterIssue=0
counterPassed=0
counterFailed=0
counterSearchPassed=0
counterSearchFailed=0
counterIssuePassed=0
counterIssueFailed=0
counterTotal=0
counterHourly=0
counterAddHourly=0
declare -a hourlyScan=('6' '0' '5' '0' '7' '2' '0' '13' '0' '18' '0' '0' '7' '0' '6' '0' '0' '1' '3' '0' '0' '0' '3' '0')
function readLogFile {
tail -n0 $logJira | \
while read line ; do
if echo "$line" | grep -e "/rest/api/2/search.*PASSED" 1>/dev/null 2>&1 ; then
echo "$date - Search and passed API action" >> $logIng
counterSearch=$((counterSearch+1))
counterPassed=$((counterPassed+1))
counterHourly=$((counterHourly+1))
counterTotal=$((counterTotal+1))
echo "$date - Total Passed API Authentication: $counterPassed" >> $logIng
echo "$date - Total search API actions: $counterSearch" >> $logIng
continue 2
elif echo "$line" | grep -e "/rest/api/2/search.*FAILED" 1>/dev/null 2>&1 ; then
echo "$date - Search and failed API action" >> $logIng
counterSearch=$((counterSearch+1))
counterFailed=$((counterFailed+1))
counterHourly=$((counterHourly+1))
counterTotal=$((counterTotal+1))
echo "$date - Total Failed API Authentication: $counterFailed" >> $logIng
echo "$date - Total search API actions: $counterSearch" >> $logIng
continue 2
elif echo "$line" | grep -e "/rest/api/2/issue.*PASSED" 1>/dev/null 2>&1 ; then
echo "$date - Issue and Passed API action" >> $logIng
counterIssue=$((counterIssue+1))
counterPassed=$((counterPassed+1))
counterHourly=$((counterHourly+1))
counterTotal=$((counterTotal+1))
echo "$date - Total Passed API Authentication: $counterPassed" >> $logIng
echo "$date - Total issue API actions: $counterIssue" >> $logIng
continue 2
elif echo "$line" | grep -e "/rest/api/2/issue.*FAILED" 1>/dev/null 2>&1 ; then
echo "$date -Issue and Failed API action" >> $logIng
counterIssue=$((counterIssue+1))
counterFailed=$((counterFailed+1))
counterHourly=$((counterHourly+1))
counterTotal=$((counterTotal+1))
echo "$date - Total Failed API Authentication: $counterFailed" >> $logIng
echo "$date - Total issue API actions: $counterIssue" >> $logIng
continue 2
fi
done
}
function runner {
while true; do
currentMinute=$(date +%S)
currentHour=$(date +%k)
currentDay=$(date +%u)
currentWeek=$(date +%W)
if [[ $currentMinute -eq 59 ]]; then
if [[ ${#hourlyScan[@]} -eq 24 ]]; then
unset hourlyScan[23]
hourlyScan=($counterHourly "${hourlyScan[@]}")
counterHourly=0
for i in "${!hourlyScan[@]}"; do
$cliScript --server $cliServer --user $cliUser --password $cliPass --action modifyPage --space "VEN" --title "API Usage Monitoring" \
--findReplaceRegex "<tr><td>$i</td><td>(\d*)</td></tr>:<tr><td>$i</td><td>${hourlyScan[$i]}</td></tr>"
done
fi
else
readLogFile
fi
done
}
runner
你能想出一个简短的例子,演示相同的问题?目前尚不清楚这与您之前的问题有何不同。 – chepner
不会把第二个while循环作为“if -eq 59”工作的其他情况吗?你有什么尝试? – lynxlynxlynx
如果我将它放在else语句中,那么它不适用于tail语句。我在外部while循环中尝试了两个while循环,但也没有工作.. –