Run a command in background and exit

2019-09-19 11:20发布

I want to run a command silently via ssh and exit the shell, but the program should continue running. I tried screen and nohup, but apparently with those it executes 3 processes instead of 1:

user:/bin/bash ./[script]
root: sudo [commandInTheScript]
root: [commandInTheScript]

What am I doing wrong?

P.S.: The thing is that I want to run this command with the Workflow app (iOS), but the app waits until the command is finished, so it freezes 'forever'

标签: linux bash ssh
3条回答
何必那么认真
2楼-- · 2019-09-19 11:44

How did you use nohup?

Eg.
nohup ruby server.rb &
Ampersand (&) is necessary to let command run in the background.

查看更多
唯我独甜
3楼-- · 2019-09-19 11:57

To run your process back ground, at end of the command you have to use &. In your case, you have to run without session since you are planning to exit from ssh after execute the command, so you need nohup

nohup <command> &
查看更多
Emotional °昔
4楼-- · 2019-09-19 12:03

nohup < command > &

This makes your command runs on background and shows its PID

查看更多
登录 后发表回答