nohup
should work for you, what was your exact command? Maybe you're missing something. Here's section from wikipedia about it:
Nohupping backgrounded jobs is typically used to avoid terminating them when logging
off from a remote SSH session. A different issue that often arises in this situation
is that ssh is refusing to log off ("hangs"), since it refuses to lose any data
from/to the background job(s). This problem can also be overcome by redirecting all
three I/O streams:
nohup ./myprogram > foo.out 2> foo.err < /dev/null &
So you could do something like:
ssh -n -f user@remotebox "sh -c 'cd /foo/bar; nohup ./myprogram > foo.out 2> foo.err < /dev/null &'"
Or if that still doesn't work, you can try screen
. It will allow you to run your process in the "background", and it will keep running after you logout.
First, ssh
over to the remote box, then from there use screen
and start your process, and you can give your screen
a session name if you want. You won't really notice anything different, but start your process in that session. You can than exit out of the screen
session by using the command Ctrl-a d
. It will look something like this:
user@remotebox:~$ screen -S foobarsession
user@remotebox:~$ startmyprocess
[detached from 4865.foobarsession]
user@remotebox:~$
You can then exit out of your ssh session, and the process will keep running. To reconnect to the screen
session later on, ssh back to the remote box and use screen -r
to reconnect. You can use screen -ls
to list the sessions.
user@remotebox:~$ screen -ls
There is a screen on:
4865.foobarsession (10/05/2012 11:10:57 AM) (Detached)
1 Socket in /var/run/screen/S-user
user@remotebox:~$ screen -r foobarsession
user@remotebox:~$ screen -ls
4865.foobarsession (10/05/2012 11:10:57 AM) (Attached)
1 Socket in /var/run/screen/S-user
user@remotebox:~$
Unlearn the need for logrotate
. You don't need logrotate
in the first place. This is a problem that has been solved since the middle 1990s.
Get yourself one or more of:
and send script standard output and standard error through a pipe to their standard input, in the normal way:
./startWebLogic.sh 2>&1 | cyclog logs/
They will write a set of automatically cycled, rotateable-on-demand, strictly size-capped logs in a directory that you specify, with no need for any additional log rotation programs at all. None of them need any superuser privileges. (In fact, far from needing or expecting superuser privileges it is best practice in their most widely known use case, logging dæmon output, to run them under unprivileged accounts.)
Further reading
Best Answer
Ok, so there are several options:
disown
You can combine
disown
and&
to push your script to the background[your_script]
can be checked by thejobs
command. Once typed you will see:And the killing can be done by
kill %1
, the1
refers to the job number seen above. This is the better alternative tonohup
as it does not leave thenohup.out
files littered all over the file system.screen
Is a "virtual" terminal which you can run from a "real" terminal (actually all terminals today are "virtual" but that is another topic for another day).
Screen
will keep running even if your ssh session gets disconnected. Any process which you start in ascreen
session will keep running with that screen session. When you reconnect to the server you can reconnect to the screen session and everything will be as if nothing happened, other than the time which passed.Excellent source: Speaking UNIX: Stayin' alive with Screen".