[英]Bash Script with Multiple if statments
因此,我試圖在大約100台服務器上設置電子郵件通知,並且使用的if腳本運行良好,但是我有一個工具,每5分鍾SSH進入每台計算機以收集統計信息。 我試圖調整腳本以忽略來自1個IP的任何ssh嘗試。 我已經絞盡腦汁,我想我已經仔細研究了關於該主題的所有可能問題。 任何幫助將是驚人的謝謝大家!!!
當前,無論誰在ssh中,腳本都會發送一封電子郵件。
#!/bin/sh
# Change these two lines:
sender="fromtest@test.com"
recepient="test@test.com"
if [ "$PAM_RUSER" != "192.168.1.10" ]; then
goto done
next
if [ "$PAM_TYPE" != "close_session" ]; then
host="`hostname`"
subject="SSH Login: $PAM_USER from $PAM_RHOST on $host"
# Message to send, e.g. the current environment variables.
message="`env`"
echo "$message" | mail "$sender" -s "$subject" "$recepient"
fi
fi
#!/bin/sh
# Change these two lines:
sender="fromtest@test.com"
recepient="test@test.com"
if [ "$PAM_RHOST" != "192.168.1.10" -a "$PAM_TYPE" != "close_session" ]; then
host="`hostname`"
subject="SSH Login: $PAM_USER from $PAM_RHOST on $host"
# Message to send, e.g. the current environment variables.
message="`env`"
echo "$message" | mail "$sender" -s "$subject" "$recepient"
fi
如果PAM_RHOST
變量等於192.168.1.10
, if
此解決方案使用其他條件來跳過if的PAM_RHOST
。 我們使用-a
(和)來指定必須同時滿足兩個條件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.