我在這篇文章中寫了一個小bash腳本:How to search for a string in a text file and perform a specific action based on the resultWhile循環執行Nagios的命令不能正常工作
我注意到,當我跑了劇本,並檢查日誌,一切都似乎是工作,但是當我看到Nagios UI中,我的文本文件中列出的幾乎一半服務器沒有禁用他們的通知。劇本的修訂版如下:
host=/Users/bob/wsus.txt
password="[email protected]"
while read -r host; do
region=$(echo "$host" | cut -f1 -d-)
if [[ $region == *sea1* ]]
then
echo "Disabling host notifications for: $host"
curl -vs -o /dev/null -d "cmd_mod=2&cmd_typ=25&host=$host&btnSubmit=Commit" https://nagios.$region.blah.com/nagios/cgi-bin/cmd.cgi" -u "bob:$password" -k 2>&1
else
echo "Disabling host notifications for: $host"
curl -vs -o /dev/null -d "cmd_mod=2&cmd_typ=25&host=$host&btnSubmit=Commit" https://nagios.$region.blah02.com/nagios/cgi-bin/cmd.cgi" -u "bob:$password" -k 2>&1
fi
done <wsus.txt>> /Users/bob/disable.log 2>&1
如果我運行鍼對手動遇到的問題的服務器的命令,它得到的Nagios的UI殘疾人,所以我有點糊塗了。僅供參考,我對Bash並不熟悉,所以這是我嘗試將此過程自動化一下的嘗試。
您是否可以從日誌中確定問題是由「while」循環未讀取缺失服務器的行引起的,還是因爲命令被調用但失敗? – Fred
將主機變量重命名爲'hostsfile =/Users/bob/wsus.txt',確保文件存在,然後將done行改爲'done <$ hostsfile >> /Users/bob/disable.log 2>&1' 。這應該做到這一點。 –
@NagiosSupport工作,謝謝!我還注意到一些「失敗」的服務器在我的文本文件中有錯誤的FQDN ...... –