1

I'm trying to run a jar file from a remote linux server using ssh The command goes like this

ssh -tt -i keyFile ubuntu@IP '
sudo chmod 777 /home/ubuntu/task.jar
sudo nohup java -jar /home/ubuntu/task.jar >> /home/ubuntu/nohup.out
'

But after running the terminal gets stuck at

nohup: ignoring input and appending output to 'nohup.out'

If I do a ctrl + C the jar stops running on the remote host

I tried adding & to the end of the command so it runs in the background like this

ssh -tt -i keyFile ubuntu@IP '
sudo chmod 777 /home/ubuntu/task.jar
sudo nohup java -jar /home/ubuntu/task.jar >> /home/ubuntu/nohup.out &
'

I get the terminal back but the jar doesn't run on the remote server at all. Am I doing something wrong?

3
  • Add a third line to the remote commands: disown Commented Jun 9, 2021 at 14:26
  • 1
    There is no good reason whatsoever to use nohup. Everything it does you can do yourself with only shell redirection and disown, and usually you don't even need disown. Commented Jun 10, 2021 at 21:26
  • Whatever you are hoping to accomplish, chmod 777 is wrong and dangerous. You absolutely do not want to grant write access to executable or system files to all users under any circumstances. You will want to revert to sane permissions ASAP (for your use case, probably chmod 755) and learn about the Unix permissions model before you try to use it again. If this happened on a system with Internet access, check whether an intruder could have exploited this to escalate their privileges. Commented Mar 15, 2022 at 8:06

2 Answers 2

0

This is normal behavior of the nohup command as its clearly stated by:

nohup: ignoring input and appending output to 'nohup.out

"Ignoring input" refers to the standard input, which happens to be your terminal session, and that's why it appears 'stuck'.

When using nohup in the foreground, you will not be able to interact with the shell until the command completes.

If you want to get your prompt back, you'd need to run it in the background. If the job isn't completing, there might be other issues, but the behavior you're experiencing is normal for the nohup command.

Sign up to request clarification or add additional context in comments.

Comments

-1

Remember not to allocate a tty for your session.
If you do that, it will not work.

So if you got any -t or -tt or -ttt and so on in your command. Thats the reason why it is not working for you.

So instead of

ssh -tt -i keyFile ubuntu@IP '
sudo chmod 777 /home/ubuntu/task.jar
sudo nohup java -jar /home/ubuntu/task.jar >> /home/ubuntu/nohup.out &
'

Use

ssh -i keyFile ubuntu@IP '
sudo chmod 777 /home/ubuntu/task.jar
sudo nohup java -jar /home/ubuntu/task.jar >> /home/ubuntu/nohup.out &
'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.