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

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

Post by Matthew Linco » Tue, 20 May 2008 02:26:25



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

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

 
 
 

1. : Weird ">" redirect behavior vs. ">>" redirect behavior

Hopefully, someone has already seen this and knows whats up.

Simple script myscript.sh:

#!/bin/sh
i=1

date
while [ 1 ]; do
   echo "Count - ${i}"
   cat /etc/system
   i=`expr ${i} + 1`
   sleep 5
done

Run it as:

nohup sh myscript.sh > /tmp/myscript.log &

Let it run for a while.  Then run:

grep Count /tmp/myscript.log | wc -l
ls -l /tmp/myscript.log
cat /dev/null /tmp/myscript.log
ls -l /tmp/myscript.log
ls -l /tmp/myscript.log
ls -l /tmp/myscript.log
grep Count /tmp/myscript.log | wc -l

The file size info on my system (Solaris 8) for the /tmp/myscript.log
is zero at first and then goes right back to where it was but a bit
more when the next iteration of the cat command output /etc/system.

Also, the first grep..wc -l command shows how many times the script
has basically looped.  The second grep will show only a couple.  This
shows that the inode is saying the file contains everything is always
did but the grep command is saying it only contains up to some of
point a buffer - maybe the output file descriptor buffer?  I'm
guessing I'm not a programmer

If you change the ">" to a ">>" with your nohup , it works as
expected. The file is zeroed out and the inode info shows it growing
as you would expect it to.

What's the differences between ">" and ">>" that makes this happen?
Running the script with ksh does the same thing.

Looks like a bug to me.

--
........................................................
......... ..- -. .. -..- .-. ..- .-.. . ... ............
.-- .. -. -... .-.. --- .-- ... -.. .-. --- --- .-.. ...

Sean O'Neill

2. Newbie:Freesco and DHCP

3. How to get "cin >> char" not to need "Enter"?

4. script to log the fingering of someone

5. >>>Compiling 2.0 problem: "asm86: Command not found" <<<

6. MS-Win helpfiles under XWin?

7. better than "$cmd 2>&1 | cat - > $logfile" ?

8. unable to mount win95 hard drive

9. Please explain ">/dev/null 2>&1"

10. "exec >foo 2>&1" without alter program's fd

11. Common Desktop "copy" & "paste" fuction keys not working in Exceed 6.1

12. GETSERVBYNAME()????????????????????"""""""""""""

13. Ooops..."libc.2.xx" --> "libc-4.2.xx"