简体   繁体   中英

Unable to exit after running command via ssh

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?

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.

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 &
'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM