apache - Bash script use of "OR" operator -
my default logrotate script apache is:
/var/log/httpd/*log { missingok notifempty sharedscripts postrotate /sbin/service httpd reload > /dev/null 2>/dev/null || true endscript }
i understand output , error redirection on line 6 can please explain purpose of || true
? , potential consequences of omitting bit?
when logrotate
utility runs postrotate
(or prerotate
) scripts, checks error code returned script. in particular, when sharedscripts
specified, error handling follows (quoted man logrotate
, emphasis added):
sharedscripts
normally, prerotate , postrotate scripts run each log rotated , absolute path log file passed first argument script. means single script may run multiple times log file entries match multiple files (such /var/log/news/* example). if sharedscripts specified, scripts run once, no matter how many logs match wildcarded pattern, , whole pattern passed them. however, if none of logs in pattern require rotating, scripts not run @ all. if scripts exit error, remaining actions not executed logs. option overrides nosharedscripts option , implies create option.
|| true
prevents http reload
command returning error condition, avoids above.
man bash
(in section "lists") describes ||
:
command1 || command2
command2
executed if , ifcommand1
returns non-zero exit status. return status of , and or lists exit status of last command executed in list.
man true
explains true
in detail, think title suffices: "do nothing, successfully".
in short, command1 || true
first executes command1
. if succeeds, result success. otherwise, executes true
, nothing successfully, , succeeds. executes command1
, succeeds
Comments
Post a Comment