發現在手冊頁的答案(RTFM,哎呀!)
firstaction/endscript
The lines between firstaction and endscript (both of which must
appear on lines by themselves) are executed (using /bin/sh) once
before all log files that match the wildcarded pattern are
rotated, before prerotate script is run and only if at least one
log will actually be rotated. These directives may only appear
inside a log file definition. Whole pattern is passed to the
script as first argument. If the script exits with error, no
further processing is done. See also lastaction.
我創建了一個firstaction
bash腳本如下檢查,如果在節點上loadbalanced IP是否存在:
#!/bin/bash
TESTCASE="$(ifconfig | grep 1.2.3.4)"
if [ -z "$TESTCASE" ]; then
/bin/false
fi
如果它返回false
,則logrotate不會繼續。
logrotate.d樣本:
/var/log/blah/*/*.log {
firstaction
/usr/local/bin/amiactive.sh > /dev/null 2>&1
endscript
...
}
我給這個一杆。感謝您的建議 – dobbs