问题
I have an Ubuntu VM dedicated as a Jenkins slave. I wrote a one-liner script to run the slave jar, and I run that script from /etc/rc.local. When I run the script manually, I get a few lines of output showing that it's working. I've tried to define the rc.local line and the script so that it stores stdout/stderr in a file, but the file is always zero length, with a modtime of when I start the process.
In the following, some fields are elided with "=stuff=".
The end of my "/etc/rc.local" looks like this:
su -c "/home/=user=/bin/jenkinsconnect" =user=
exit 0
The "jenkinsconnect" script looks like this:
#! /bin/bash
java -jar /home/=user=/opnfv_slave_root/slave.jar -jnlpUrl https://=host=/ci/computer/att-build/slave-agent.jnlp -secret =secret= 2>&1 > /home/=user=/jc.log
As I said, "/home/=user=/jc.log" is always zero length, and the modtime is when I started the process.
回答1:
The 2>&1 > file
syntax will not work. You should either:
- use
&>
for directing both stderr and stdout to a file, or surround the entire command with parentheses to capture the output:
(java -jar /home/=user=/opnfv_slave_root/slave.jar ... 2>&1) > /home/=user=/jc.log
来源:https://stackoverflow.com/questions/29654808/jenkins-slave-process-on-ubuntu-not-showing-any-logging