Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

In Linux, I've written some scripts to be executed during boot and played around with the various ways of installing them. For larger scripts I'll put in /etc/init.d and link the appropriate /etc/rc.d/rc?.d runlevels. For smaller scripts, I'll append to /etc/rc.d/rc.local. This process seems to be running smoothly.

Now I've tweaked one of my scripts and it is failing. I'm having a heck of a time diagnosing it because I can't seem to capture the error output. I've checked /var/log/messages and poked around the rest of /var/log but can't find anything of use.

Does anyone know:

  1. are these error messages automatically captured somewhere?
  2. if not, how can I capture the stdout/stderr from my init.d scripts?

Thanks in advance.

share|improve this question
1  
serverfault.com/a/321926/59925 –  quanta Dec 17 '11 at 17:19
    
@quanta that has some helpful tips, thanks. –  McKAMEY Dec 17 '11 at 18:10

3 Answers 3

up vote 4 down vote accepted

1.: No - they go to STDOUT (if you use echo) or STDERR (if you use echo >&2).

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.

share|improve this answer
    
Thanks everyone for the variety of approaches. I'm marking this one as the solution since it covers the various aspects most completely. –  McKAMEY Dec 19 '11 at 18:36

Write a wrapper script that calls your script and redirects the output to a files

#!/bin/bash

    /path/to/your/script &>/path/to/logfile
share|improve this answer

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
share|improve this answer
    
Thanks, this is closer to what I was looking for. I know how to redirect I/O but I didn't know how to call into the logger. –  McKAMEY Dec 17 '11 at 18:11
    
Is [ -r ... ] a test to check if it exists? –  McKAMEY Dec 17 '11 at 18:14
    
Yes, check if the file is readable. –  ott-- Dec 17 '11 at 18:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.