LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-22-2014, 01:18 AM   #1
sarfrazs
LQ Newbie
 
Registered: Aug 2014
Posts: 2

Rep: Reputation: Disabled
> not writing output to file


Dear All, Kindly help in debugging an issue where in my server using the > operator does not write output to file, although it shows output in putty.
Server SunOS 5.10
Thanks
 
Old 08-22-2014, 02:47 AM   #2
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 304

Rep: Reputation: 121Reputation: 121
Could you tell us more? You provided very little information for us to work with, but I will try to help.

The > operator will redirect the normal output (stdout) to a file, but not error messages (stderr). If you wish to output both stdout and stderr to a file, use the 2> operator, or &> if your system has it:
Code:
# redirect stdout but not stderr:
date > $logfile

# redirect stderr but not stdout:
date 2> $logfile

# redirect both stdout and stderr in the old way:
date > $logfile 2>&1

# redirect both stdout and stderr in the new way (since bash 4):
date &> $logfile
Next point: The > operator overwrites the previous file. Use >> to append to an existing file.
Code:
# (see above comments)

date >> $logfile

date 2>> $logfile

date >> $logfile 2>&1

date &>> $logfile
Finally, bear in mind that > and >> write to the current working directory, unless you specify the full path of the output file. Perhaps your output has been redirected to a file but you are looking for it in the wrong directory.

Last edited by Beryllos; 08-22-2014 at 02:56 AM.
 
Old 08-22-2014, 07:38 AM   #3
sarfrazs
LQ Newbie
 
Registered: Aug 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thank you for your time, Beryllos. I have tried the following

Code:
ls >output.txt

ls >>output.txt

nohup READGFILE -d /SASG /D0 >output.txt 2>output.err &
This is creating a 0kb file only it doesn't have any data. I have tried both > and >>. And the directory contains files it is not empty.



Quote:
Originally Posted by Beryllos View Post
Could you tell us more? You provided very little information for us to work with, but I will try to help.

The > operator will redirect the normal output (stdout) to a file, but not error messages (stderr). If you wish to output both stdout and stderr to a file, use the 2> operator, or &> if your system has it:
Code:
# redirect stdout but not stderr:
date > $logfile

# redirect stderr but not stdout:
date 2> $logfile

# redirect both stdout and stderr in the old way:
date > $logfile 2>&1

# redirect both stdout and stderr in the new way (since bash 4):
date &> $logfile
Next point: The > operator overwrites the previous file. Use >> to append to an existing file.
Code:
# (see above comments)

date >> $logfile

date 2>> $logfile

date >> $logfile 2>&1

date &>> $logfile
Finally, bear in mind that > and >> write to the current working directory, unless you specify the full path of the output file. Perhaps your output has been redirected to a file but you are looking for it in the wrong directory.
 
Old 08-22-2014, 11:58 AM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,959

Rep: Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268
Quote:
Originally Posted by sarfrazs View Post
Code:
ls >output.txt

ls >>output.txt

nohup READGFILE -d /SASG /D0 >output.txt 2>output.err &
That redirection will truncate output.txt to zero length and then redirect the stdout from the nohup process to that now empty file. Since that removes the output from the previous ls processes, I doubt that is what you intended.
 
Old 08-22-2014, 02:58 PM   #5
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 304

Rep: Reputation: 121Reputation: 121
Quote:
Originally Posted by sarfrazs View Post
Thank you for your time, Beryllos. I have tried the following

Code:
ls >output.txt

ls >>output.txt

nohup READGFILE -d /SASG /D0 >output.txt 2>output.err &
This is creating a 0kb file only it doesn't have any data. I have tried both > and >>. And the directory contains files it is not empty.
I don't know. Does output.err contain anything? What happens if you do it without the nohup? Does READGFILE do anything? If I do the following, it works as expected:
Code:
nohup ls >output.txt 2>output.err
Then the output of ls appears in output.txt and an error message from nohup appears in output.err. Does it work that way for you?

Last edited by Beryllos; 08-22-2014 at 05:19 PM.
 
Old 08-22-2014, 03:07 PM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
is READGFILE a long process? The output to output.txt and output.err will be buffered, which means you might not see anything for some time, depending on how quickly READGFILE is printing it out.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
NFS Large File Copies Fail - Error writing to file: Input/output error deck- Linux - Server 7 07-27-2013 12:14 PM
writing output to a comma separted file nano2 Solaris / OpenSolaris 7 03-27-2012 08:04 AM
Writing Screen output to a file and emailing vijayrc Linux - Newbie 7 06-08-2009 11:54 PM
writing output of a program to a file only when all of it is ready pgb205 Linux - Software 4 12-10-2008 03:01 PM
writing output to file Hockeyfan Linux - General 3 10-24-2005 09:02 PM


All times are GMT -5. The time now is 08:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration