Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"nohup rsync ... >my.log &2>1" does not work

1,443 views
Skip to first unread message

Matthew Lincoln

unread,
May 18, 2008, 1:26:25 PM5/18/08
to
I logged in through a command shell on a Linux system and entered a command:

nohup rsync ... >my.log &2>1

I expected that after the command issue the command prompt

ml@server [/]#

gets visible again.

But the ssh terminal is blocked as if I would have NOT entered "nohup".

Why is the rsync command still running in foreground although I prepended the command with "nohup" ?

Matthew

Luuk

unread,
May 18, 2008, 1:35:05 PM5/18/08
to
Matthew Lincoln schreef:

try:
rsync ... >my.log 2>&1 &

--
Luuk

us...@domain.invalid

unread,
May 18, 2008, 2:50:00 PM5/18/08
to
Matthew Lincoln schrieb:

> I logged in through a command shell on a Linux system and entered a command:
>
> nohup rsync ... >my.log &2>1
>
You need to append & on the end like:

nohup rsync ... >my.log &2>1 &

That way, the process is started in background
or you can stop the running process with Ctrl+Z and then resume it
in background with bg <jobnumber>

Greets
Chris

Bill Marcum

unread,
May 18, 2008, 3:19:03 PM5/18/08
to
You have to add "&" to run the command in the background.

Wayne

unread,
May 18, 2008, 4:00:48 PM5/18/08
to

Two problems:

"nohup" does not put jobs into the background automatically.
So to get back the prompt you need to add '&' at the end of
the command line.

nohup currently doesn't close stdin, so your session may hang
when you attempt to log out. This is fixed in the next version
of the POSIX/SUS (and I believe Gnu nohup already), but it
can't hurt to make sure.

So you should run this command as:

nohup rsync ... </dev/null &

There is no need to redirect either stdout or stderr, as
nohup will do that for you, to the file ./nohup.out. But
if you want to redirect the output yourself, please note
the correct syntax is "... 2>&1" and not "... &2>1".

Hope this helps!

-Wayne

david

unread,
May 18, 2008, 4:05:48 PM5/18/08
to
On Sun, 18 May 2008 17:26:25 +0000, Matthew Lincoln rearranged some
electrons to say:

Try running it in the background... &

Joachim Schmitz

unread,
May 19, 2008, 2:30:32 AM5/19/08
to
Matthew Lincoln wrote:
> I logged in through a command shell on a Linux system and entered a
> command:
>
> nohup rsync ... >my.log &2>1
Shouldn't that be ... 2>&1?

>
> I expected that after the command issue the command prompt
>
> ml@server [/]#
>
> gets visible again.
>
> But the ssh terminal is blocked as if I would have NOT entered
> "nohup".
>
> Why is the rsync command still running in foreground although I
> prepended the command with "nohup" ?

Because nohup doesn't put it into the background, you'd still need & for
that.

nohup rsync ... >my.log 2>&1 &

Bye, Jojo


Robert Harris

unread,
May 19, 2008, 4:10:50 AM5/19/08
to

nohup does not run commands in the background.

"man nohup" will tell you what it does.

Robert

Tobias Nissen

unread,
May 19, 2008, 5:29:40 AM5/19/08
to
Matthew Lincoln wrote:
> I logged in through a command shell on a Linux system and entered a
> command:
>
> nohup rsync ... >my.log &2>1

First of all: You mean 2>&1, right?

> I expected that after the command issue the command prompt
>
> ml@server [/]#
>
> gets visible again.
>
> But the ssh terminal is blocked as if I would have NOT entered
> "nohup".
>
> Why is the rsync command still running in foreground although I
> prepended the command with "nohup" ?

Do you use the GNU version of hangup or something your shell has
builtin? The behaviour of GNU's hangup is not to spawn a seperate
process, but I don't know about the other implementations.

If you explicitly want to spawn a process, do so:

nohup rsync ... &

Recognize the ampersand at the end of the rsync-command.

Also, your redirection >my.log 2>&1 won't work as expected, because
nohup writes output to a file named 'nohup.out'.

Instead of nohup, you can also use screen with its detach and reattach
features.

birre

unread,
May 19, 2008, 8:41:15 AM5/19/08
to

Nohup don't run things in background, it just use /dev/null as input, and
some other things, so you can logout while you run it in background.

In your case the output redirection is still done by your current shell, and
not by nohup.

To understand what I mean, do ssh othermachine df >df.out , and you will find
df.out on your local machine, not on the remote machine, while
ssh othermachine 'df > df.out' will create df.out on the remote machine.

eg, try something like:
(nohup rsync ... >my.log &2>1) &

Or just nohup rsync ... & , and use the default nohup.out

Or , just make a script, like this:
#!/bin/bash
(
rsync .......
) >my.log &2>1

And just do nohup script &

/bb

Scott McMillan

unread,
May 19, 2008, 10:28:12 AM5/19/08
to
On 18 May 2008 17:26:25 GMT, kmlinc...@hotmail.com (Matthew
Lincoln) wrote:

Couple of problems here...

>nohup rsync ... >my.log &2>1

nohup does not put a command into the background, & does
&2>1 will create a file called 1

I think what you are looking for is something like:

nohup rsync <rsync options> >my.log 2>&1 &


Scott McMillan

Tobias Nissen

unread,
May 19, 2008, 3:57:57 PM5/19/08
to
Matthew Lincoln wrote:
> I logged in through a command shell on a Linux system and entered a
> command:
>
> nohup rsync ... >my.log &2>1

First of all: You mean 2>&1, right?

> I expected that after the command issue the command prompt


>
> ml@server [/]#
>
> gets visible again.
>
> But the ssh terminal is blocked as if I would have NOT entered
> "nohup".
>
> Why is the rsync command still running in foreground although I
> prepended the command with "nohup" ?

Do you use the GNU version of hangup or something your shell has

Ian Petts

unread,
May 19, 2008, 11:49:59 PM5/19/08
to
On 2008-05-18, Matthew Lincoln <kmlinc...@hotmail.com> wrote:
> nohup rsync ... >my.log &2>1

> I expected that after the command issue the command prompt

> But the ssh terminal is blocked as if I would have NOT entered "nohup".

nohup doesn't run the command in the backgound, but it stops the script
from exiting when you log out of the shell.

Try:


nohup rsync ... >my.log 2>&1 &

2>&1 redirects stderr to the same place stdout is going
the & at the end puts the command in the background.

Regards,
Ian.

birre

unread,
May 20, 2008, 8:21:32 AM5/20/08
to

Sorry, I didn't see the &2>1 thing :-(
Yes, it is 2>&1
/bb

Patrick Cao Huu Thien

unread,
May 23, 2008, 11:07:53 AM5/23/08
to
Matthew Lincoln a dit le 05/18/2008 07:26 PM:

> I logged in through a command shell on a Linux system and entered a command:
>
> nohup rsync ... >my.log &2>1

If you use bash, you have a syntax error. Use:

$ nohup rsync ... >my.log 2>&1 &

or quicker:

$ nohup rsync &> my.log &

see more here: http://www.tldp.org/LDP/abs/html/io-redirection.html

--
Patrick CAO HUU THIEN
email: patrick point cao_huu_thien arobase upmc point fr
gpg key ID: 1024D/58D16D27 sur pgp.mit.edu
fingerprint: D7B8 7DFB 479C A02E 48A2 383C 0005 4A33 58D1 6D27

blm...@myrealbox.com

unread,
May 24, 2008, 2:59:25 PM5/24/08
to
In article <2008051921575...@movb.de>,
Tobias Nissen <t...@movb.de> wrote:
> Matthew Lincoln wrote:

[ snip ]

> > Why is the rsync command still running in foreground although I
> > prepended the command with "nohup" ?
>
> Do you use the GNU version of hangup or something your shell has
> builtin? The behaviour of GNU's hangup is not to spawn a seperate
> process, but I don't know about the other implementations.
>
> If you explicitly want to spawn a process, do so:
>
> nohup rsync ... &

A belated possibly-nitpick: Doesn't rsync run as a separate process
in any case? and what the ampersand does it allow the original (shell)
process to continue without waiting for the rsync process to finish?

[ snip ]

--
B. L. Massingill
ObDisclaimer: I don't speak for my employers; they return the favor.

0 new messages