Saving nohup output to a file other than nohup.out


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Saving nohup output to a file other than nohup.out
# 1  
Old 12-06-2013
Saving nohup output to a file other than nohup.out

Shell : bash
OS : Oracle Linux 6.4

I want to save the ouput of a nohup command to file other than nohup.out . Below are my 3 attempts.

For both Attempt1 and Attempt2 , the redirection logs the output correctly to the output file. But I get the error "ignoring input and redirecting stderr to stdout" in the shell just after the nohup command is issued.

I tried Attempt3 with 2>&1. This one also logged to output file. This time I didn't get the error "ignoring input and redirecting stderr to stdout" . But I got "nohup: ignoring input" as the first line in the error log.

How can I get an error-less redirection of nohup output file ?

I am creating a formal document detailing steps for a critical activity. Althoug the below executions work fine , I want to get rid of those ignorable errors. Any idea how I can get rid of those errors ?



Code:
$ cat test.sh
#!/bin/bash
echo -e "hello world Start"
sleep 10
echo -e "hello world End"
mumbojumbo
$

## Attempt1.
Code:
$
$ nohup test.sh >MyOutput.log &
[1] 6535
$ nohup: ignoring input and redirecting stderr to stdout

$
$ cat MyOutput.log
hello world Start
hello world End
./test.sh: line 5: mumbojumbo: command not found
[1]+  Exit 127                nohup test.sh > MyOutput.log

### Attemp2 (a space after the redirection character > )
Code:
$ nohup test.sh > MyOutput.log &
[1] 9914
$ nohup: ignoring input and redirecting stderr to stdout

$
$ cat MyOutput.log
hello world Start
hello world End
./test.sh: line 5: mumbojumbo: command not found
[1]+  Exit 127                nohup test.sh > MyOutput.log

Attempt3. using 2>&1

Code:
$ nohup test.sh > MyOutput.log 2>&1 &
[1] 11773
$
$
$
$
$ cat MyOutput.log
nohup: ignoring input
hello world Start
hello world End
./test.sh: line 5: mumbojumbo: command not found

# 2  
Old 12-06-2013
Try redirecting stdin from /dev/null.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 12-06-2013
Redirect stdin to get rid of the last error:
Code:
nohup test.sh > MyOutput.log 2>&1 </dev/null &

This User Gave Thanks to cero For This Post:
# 4  
Old 12-06-2013
Code:
nohup test.sh &>MyOutput.log &

This User Gave Thanks to in2nix4life For This Post:
# 5  
Old 12-06-2013
Thank you Cero, RudiC

Cero's (and RudiC's) solution has worked
Code:
nohup test.sh > MyOutput.log 2>&1 </dev/null &

But I didn't quite understand how 'redirecting stdin from /dev/null' work.

Regarding commands to accept Standard Input: I've only used things like below in my career.
sort < unsorted_names_list.txt

And I have only bit bucket /dev/null to discard errors like below.
find / -name "HelloWorld" 2>/dev/null

Can you explain how redirecting stdin from /dev/null got rid of the error ?
# 6  
Old 12-06-2013
man nohup:
Quote:
... If standard input is a terminal, redirect it from /dev/null. ...
This User Gave Thanks to RudiC For This Post:
# 7  
Old 12-08-2013
Thank you RudiC.

But , what does re-directing input from /dev/null even mean ?

Code:
$ wc < /dev/null
      0       0       0
$
$
$ echo < /dev/null

$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nohup not give expected output. Non-stop running process

Hello, I am trying to make a bash script, I tested nohup but it did not help me. My code is: ffmpeg -i $input_url -c:v copy -c:a copy -listen 1 -f mpegts http://localhost:port/live/test When I open it in VLC, it starts feeding my screen and I see bitrate values. When I stop watching it,... (4 Replies)
Discussion started by: baris35
4 Replies

2. UNIX for Dummies Questions & Answers

How do I send output of a background process to a file other than nohup.out?

I have a question. I will be running a background process using nohup and & command at end. I want to send output to a file say myprocess.out. So will this command work? nohup myprocess.ksh > myprocess.out & Thanks in advance guys !!! :) (3 Replies)
Discussion started by: vx04
3 Replies

3. Shell Programming and Scripting

grep from the nohup.out file

Hi, I have one shell script, which run another one script inside in nohup mode. I want to search one string from the nohup.out file in the same shell script itself .Can anyone help me?? Please find the code below: total_ear=`cd ear ; ls *.ear | wc -l | tr -d ' '` for ear in `cd ear ; ls... (1 Reply)
Discussion started by: ckchelladurai
1 Replies

4. UNIX for Dummies Questions & Answers

How to grep string from nohup.out file

Hi, I have one shell script, which run another one script inside in nohup mode. I want to search one string from the nohyup.out file in the same mail shell script itself .Can anyone help me?? Please find the code below: total_ear=`cd ear ; ls *.ear | wc -l | tr -d ' '` for ear in `cd ear ; ls... (0 Replies)
Discussion started by: ckchelladurai
0 Replies

5. Shell Programming and Scripting

extending the line length of nohup output

Hi I'm backgrounding matlab jobs using nohup. My foreground programs are written for an xterm that has 132 columns. When I use nohup and redirect the output to nohup.out, the default appears to be something like 72 columns, which breaks up my formatted screen output from matlab commands... (1 Reply)
Discussion started by: LeoSimon
1 Replies

6. Shell Programming and Scripting

nohup output on screen for some time

Hi, I'm executing a binary with nohup in a menu(shellscript) and output is going to nohup.out fine. I need few lines of nohup.out should be displayed on screen so that I will come to know the process is successfully started and continue with other options in my menu. Thanks in advance. (3 Replies)
Discussion started by: axes
3 Replies

7. Shell Programming and Scripting

output nohup file containg the PID

Hi to everybody. Is it possible to nohup a process and redirect the output to a file containing the PID? E.g. if nohup filename > out.nohup associate the PID=8074 to filename, is it possible to call the output file something like out_8074.nohup instead of out.nohup? By this way it would... (0 Replies)
Discussion started by: plsrn
0 Replies

8. UNIX for Dummies Questions & Answers

Route the logs to different file other than nohup.out

Hi guys Right now the standard out and standard err are going to nohup.out file I wanted to route to some other name specific files so that it will be easy to research the logs Example I have this line in my script nohup execute receiptLoaderStart & which is routing the logs to... (6 Replies)
Discussion started by: pinky
6 Replies

9. UNIX for Dummies Questions & Answers

I want to copy the text output from a 'nohup.out' file.

Hello, I have a nohup.out file that, when executed, outputs a spreadsheet file with four-to-seven columns of number. I want to copy this output (in its entirety), so that I could then paste it on excel@ , or Notepad@. Please help, thanks. (3 Replies)
Discussion started by: Iamthe great
3 Replies

10. Shell Programming and Scripting

capture nohup log file

Hi, I am running my script using nohup, but I am not able to capture the log file for that process could naybody please help... Here is what I am doing.... nohup ./script & 1>/home/user1/log.txt but I am not able to capture the log.....Is there anyother way I can capture the log... (2 Replies)
Discussion started by: mgirinath
2 Replies
Login or Register to Ask a Question