LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-27-2008, 12:29 PM   #1
kissaki
LQ Newbie
 
Registered: Dec 2008
Posts: 3

Rep: Reputation: 0
redirect stdout to file produces blank file


I cannot redirect output from commands such as iptables, iptables-save, and ifconfig. For example, any of the following DOESN'T work ( as root ):
Code:
iptables > tmp
iptables-save > tmp
ifconfig > tmp
The file tmp is ALWAYS blank, that is, 0 bytes in size. Wackier things DO work, such as:
Code:
echo "`iptables-save`" > tmp
iptables-save | tee tmp
Other commands like:
Code:
ls > tmp
DO work as expected.

Note that this problem happens regardless if I log-in remotely via ssh or locally on the computer in question. I am clueless as to what is causing this. Any ideas?

The box is running 2.6.25-14.fc9.i686 and boots to runlevel 3. The modifications I've made to the box since installing the OS are things like compiling/installing latest OpenSSH,OpenSSL,httpd,BerkeleyDB,subversion,zlib etc -- nothing really out of the ordinary I'd say.
 
Old 12-27-2008, 12:48 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
If I am not mistaken, the redirect operator (>) redirects **anything** that would normally go to the screen as "stdout".

Example:
iptables does not exist on my machine..

"iptables" produces an error message (on the screen)
"iptables" > tmp same error message, nothing in the file
"iptables" 2> tmp nothing on the screen, error message in the file

"ifconfig > tmp" works as expected
 
Old 12-27-2008, 12:57 PM   #3
kissaki
LQ Newbie
 
Registered: Dec 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Sorry, I should have stated:
Code:
iptables -L
in my original example. I also have /sbin in my path. Nonetheless, all of the following give me blank file output:
Code:
iptables -L > tmp
/sbin/iptables -L > tmp
iptables 2> tmp
/sbin/iptables 2> tmp
When I don't redirect the output to stdout is as expected.
 
Old 12-27-2008, 02:43 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I cannot duplicate this. I even installed iptables to test that specifically
 
Old 12-27-2008, 07:41 PM   #5
dquick1
LQ Newbie
 
Registered: Dec 2008
Location: Geelong, Australia
Distribution: Fedora
Posts: 8

Rep: Reputation: 0
Double check you do not have a tmp directory in the directory you are working in?

Also, try this to redirect all output stdout, stderr etc to a file in another directory;

Code:
$iptables -L > /tmp/afile 2>&1

Also test to see if redirection will work to tmp in the directory you are in:

Code:
$ echo This is a line of text > tmp
or

Code:
$ echo This is a line of text > /tmp/afile.txt
Damien
 
Old 01-06-2009, 03:28 AM   #6
kissaki
LQ Newbie
 
Registered: Dec 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Solved

Turns out it was SELinux preventing the write.
 
  


Reply



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
How to redirect standard stdout to multi stdout ( Bash )? john.daker Programming 4 11-03-2008 11:20 PM
How can I redirect the output of a file to another file within the file prakash.akumalla Linux - Newbie 28 10-30-2008 12:28 PM
trying to redirect text to a file to cat at later point. says file doesn't exist. dr_zayus69 Programming 1 10-02-2005 08:10 AM
stdout to file Machiaveli Programming 8 09-04-2005 08:53 AM
How do I redirect something to a file without it overwriting the destination file??? nikold01 Linux - General 8 09-09-2004 02:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:15 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
Open Source Consulting | Domain Registration