0

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!

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

3 Answers 3

4

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.

1
  • (command &) worked for me where I was having ioctl error with nohup. May 10, 2012 at 12:22
1

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.

1
  • & 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. Mar 1, 2011 at 9:05
1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .