Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm running this command:

$ nohup command > foo.out 2> foo.err < /dev/null &

My problem is that even though nohup makes my command run in the background, it prints out something like this to my terminal:

[1] 27918

How do I make it not output the job number? I just want it to do it in the background without telling me anything. On Mac OS X, that's exactly what happens, so I'm a little annoyed that it works differently on Ubuntu...

Thanks for the help!

share|improve this question
2  
The [1] 27918 is coming from the & not the nohup –  Majenko Mar 1 '11 at 8:50
    
Thanks Matt, that did it. Now how do I close this question... –  hora Mar 1 '11 at 8:53
    
The way to do that is mark an answer as accepted using the checkmark next to it. –  Dennis Williamson Mar 1 '11 at 10:06
    
See superuser.com/faq section "How do I ask questions" –  grawity Mar 1 '11 at 10:10
add comment

3 Answers 3

Job information is displayed by your shell, not nohup.

You could try this alternative:

(yourcommand&)

( spawns a subshell, which handles job control differently.

(I have nh() { ("$@" &); } in my ~/.bashrc, so I can type nh command to do the same thing.)

Another, different way:

setsid yourcommand

Edit: It seems that (setsid yourcommand &) is the best combination, since it detaches from the tty and works equally in interactive and script modes.

share|improve this answer
    
(command &) worked for me where I was having ioctl error with nohup. –  Shahzada Hatim May 10 '12 at 12:22
add comment

The [1] 27918 is coming from the & not the nohup.

Put the command you want to run in the background inside a script file:

#!/bin/sh
/path/to/command & >/dev/null 2>/dev/null

and then call that with nohup

nohup sh /path/to/my/script > foo.out 2> foo.err < /dev/null

The output of & is then redirected to /dev/null inside the script.

share|improve this answer
    
& is only a command terminator, it doesn't output anything and you cannot redirect it. In interactive mode, the job line is printed by the shell; in non-interactive (including scripts), it remains quiet. Your inner redirects apply to output of the command itself, and I do not think the outer redirects will override them. –  grawity Mar 1 '11 at 9:05
add comment

Just as the one above mentioned (Thanks, by the way).

Within a script named test.ksh:

#!/bin/ksh
./test2.ksh >/dev/null
nohup ksh test2.ksh < /dev/null
echo  "whatever"

Where test2.ksh is another script (or may be a command):

#!/bin/ksh
max=10
for ((i=2; i<=$max; ++i )) ; do
    echo -e "\n Hello world "
done

Then, run:

~> ksh test.ksh

and the output is:

nohup: appending output to `nohup.out'
whatever
~>

It worked for me

If you keep the & in the redirection

./test2.ksh & >/dev/null

It will print both in the tty and the file .out

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.