How to find error messages from Linux init.d/rc.d scripts?
Solution 1:
No - they go to STDOUT (if you use
echo
) or STDERR (if you useecho >&2
).Your scripts have to write to logs and/or syslog on their own (your distribution might contain some init.d functions that might help there - add your distribution to your question).
If you go for logs look for the tee
command. If you go for syslog look at logger
. You can combine them in any way you want to.
Solution 2:
Write a wrapper script that calls your script and redirects the output to a files
#!/bin/bash
/path/to/your/script &>/path/to/logfile
Solution 3:
You could make a function to echo the message to both the screen and to syslog, something like this:
LOGGER="/usr/bin/logger -t $myScript" # check the location of logger for your system
myEcho () {
echo "$1"
$LOGGER "$1"
}
You could also put that into a separate file and include it into your scripts with
#!/bin/bash
myScript=$(basename $0)
[ -r /myFunctions/myecho ] && . /myFunctions/myecho
Solution 4:
Messages from init scripts are generally not captured anywhere. Thus, you need to implement a way to do it yourself. A good idea is to use logger
to send all output to syslog. This example will send stdout and stderr to syslog:
exec 1> >(logger -s -t $(basename $0)) 2>&1
I found it in this great article: http://urbanautomaton.com/blog/2014/09/09/redirecting-bash-script-output-to-syslog/.