I'm trying to start a proccess on remote server with ssh. I need to log stdout on target server (not the local one)

Here is the script:

sshpass -p mypwd ssh [email protected] nohup java -jar /tmp/jenkins/myjar.jar > log.log 2>&1 &

Process starts fine, but logs are created on local server. Checked with

find . -name 'log.log'

I tried to wrap nohup command to double quotes

sshpass -p mypwd ssh [email protected] "nohup java -jar /tmp/jenkins/myjar.jar > log.log 2>&1 &"

Process starts fine, but no logs are present on both servers.

How can I make nohup send stdout to log file on remote server?

  • The last command should at least have created log.log file on the server, or have failed if creating the file was impossible. Are you sure you know the directory where the command run? Did you look in the right directory? What if you redirected to a file with absolute path? Jan 14, 2019 at 12:47
  • @Kamil Maciorowski, I've scanned entire server (from root) & checked manually the home folder and folder with jar. No file
    – Ermintar
    Jan 14, 2019 at 12:50

1 Answer 1


The point is that nohup must go before sshpass command to log all the output; every command with no nohup goes like this: nohup command or nohup command > output.log 2>&1

  • I tried to use nohup sshpass -p mypwd ssh [email protected] java -jar /tmp/jenkins/myjar.jar > log.log 2>&1 & the result was the same.
    – Ermintar
    Jan 14, 2019 at 13:24
  • What worked for me: sshpass -p mypwd ssh [email protected] "java -jar /tmp/jenkins/myjar.jar > log.log &" I'm wondering why
    – Ermintar
    Jan 14, 2019 at 13:26
  • I should have worked to you; sometimes the redirection 2>&1 may cause interferences, if you type nohup shpass -p mypwd ssh [email protected] 'java -jar /tmp/jenkins/myjar.jar' > log.log it should redirect the output; the only point is that only the output would be redirected.
    – Dasel
    Jan 14, 2019 at 13:32

You must log in to answer this question.

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