5

We are starting our Jenkins CI with the following bash command that I would like understand. Could someone explain what is doing (the only bit I get is "java -jar jenkins.war"). Thanks!

nohup java -jar jenkins.war > $HOME/jenkins.log 2>&1 < /dev/null &

2 Answers 2

13

The nohup means it will continue to run when you exit the shell.

The > means redirect the standard output to a file

The file it is being redirected to is $HOME/jenkins.log. You can find the value of $HOME by running echo $HOME

2>&1 means redirect standard errors to standard output, so in this example will also go into $HOME/jenkins.log.

The < /dev/null means read data in from /dev/null. So if the script is expecting input it will read that instead of waiting for user input.

And the & means run as a background task, and return you to the command line.

If you want more detail, ask in the comments.

4
  • you was too quick for me :+
    – Rinzwind
    Feb 8, 2012 at 14:56
  • For me, too as it seems :-D
    – Michael K
    Feb 8, 2012 at 14:57
  • This question has links to some documentation you can use to learn a bit more about the command line. askubuntu.com/questions/85709/…
    – roadmr
    Feb 8, 2012 at 15:05
  • Rinzwind, Michael K: Yes but at the expense of poorly formatted answer. Feb 8, 2012 at 15:14
3
nohup

detaches the following command from the current terminal session, which prevents the process from being closed on terminal exit.

java

then runs the java VM with the options

-jar jenkins.war

which tells java to run the main class from the jar-archive jenkins.war

>

forwards the standard output (what usually appears in the terminal) into the given file, in this case into $HOME/jenkins.log

2>&1

means that the optput of the error channel is connected to the output of the standard output channel.

< /dev/null

sends "nothing" as input stream to the java command.

Finally & forces the task into backgrount such that the control returns to the prompt.

2
  • Actually, /dev/null is not the input stream consisting of zeroes (that's /dev/zero), it is an input stream that has null content. In other words, if the java process tries to read something from the standard input, it will immediately read end-of-file. Feb 15, 2012 at 5:33
  • You re right, corrected it.
    – Michael K
    Feb 15, 2012 at 6:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .