Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a .sh script that starts a java service of mine (I didn't write this).

Can someone explain how this actually executes?

start() {
 ..
 ..

   # setup classpath
  . $ROOT/bin/_cp.sh

  RUN="java -Dlog.root=$VAR $JOPTS $CP $MAIN -v"

  # start
  $RUN 2>>$OUT_FILE >>$OUT_FILE &

}

When start gets called, it builds sets the variables for the options and class path (java stuff), but when does this line do?

$RUN 2>>$OUT_FILE >>$OUT_FILE &

Is $RUN something built in at all?

I want to convert this over to a upstart script, and upstart requires me to use exec like:

script
        [ "$enabled" = "1" ] || [ "$force_start" = "1" ] || exit 0
        # Setup Serviio specific properties
        JAVA_OPTS="-Djava.net.preferIPv4Stack=true -Djava.awt.headless=true -Dderby.system.home=$SERVIIO_HOME/library -Dserviio.home=$SERVIIO_HOME -Xmx512M -Xms20M -XX:+UseParNewGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20"
        # construct classpath
        cd $SERVIIO_HOME
        CLASSPATH="config"
        for i in lib/*.jar; do
                CLASSPATH="$CLASSPATH:$i"
        done
        # write to syslog - for debugging
        # logger -t $0 -- "starting: /usr/bin/java $JAVA_OPTS -classpath $CLASSPATH org.serviio.MediaServer"
        exec /usr/bin/java $JAVA_OPTS -classpath $CLASSPATH org.serviio.MediaServer
end script
share|improve this question
    
RUN="java -Dlog.root=$VAR $JOPTS $CP $MAIN -v" creates a bash variable RUN. I think $RUN 2>>$OUT_FILE >>$OUT_FILE & prints the contents of RUN into two files. –  Seth Feb 19 '13 at 4:12

1 Answer 1

As Seth mentioned, $RUN is defined previously in the script with the RUN="java ..." line. The line is executed, and standard output and standard error messages are both appended to the $OUTFILE which presumably is also defined in the script (or specified by commandline parameter).

2>>file

is bash code for redirecting the stderr stream. By default, stdout and stderr are both output to the tty (your bash prompt) where they are displayed, but you can redirect the output. By default, using >> file will only redirect the standard output (stuff that is printed using echo - this is the usual form of output for most programs. However, when programs wish to put out an error, this will go on the standard error output stream, which (by default) is printed to the terminal, and is NOT redirected using >>. To redirect the error stream as well (perhaps for error logging) you use 2>> file, which will append it to file. Interestingly, the same effect as in the script could be achieved by using &>> $OUTFILE, which is shorthand for "redirect both stdout and stderr".

share|improve this answer

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.