Redirecting stderr problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Redirecting stderr problem
# 1  
Old 08-27-2008
Redirecting stderr problem

Code:
% ls -ld /usr /foo
ls: /foo: No such file or directory
drwxr-xr-x  14 root  wheel  512 May 18 02:49 /usr
% ls -ld /usr /foo 1>/dev/null/
/dev/null/: Not a directory.
% ls -ld /usr /foo 2>/dev/null/
/dev/null/: Not a directory.


^^Why why why doesn't this work for me. Furthermore, where is stdout on the last?

I'm trying to prevent 'find' from barfing the permission denied errors if anybody has experienced that. Wondering if I'm doing something wrong or how to further examine stderr's config on the server.

Side note: Please forgive if this answer is already posted as I've tried searching here and google with no luck. Thanks in advance for your 0.Smilie
# 2  
Old 08-27-2008
ls -ld /usr /foo 2>/dev/null without the final /
# 3  
Old 08-28-2008
Sorry but this did't work for me..
Code:
> ls -ld /usr 
drwxr-xr-x  14 root  wheel  512 Dec 21  2007 /usr
> ls -ld /usr /foo 2>/dev/null
ls: /foo: No such file or directory
ls: 2: No such file or directory

So again, why is it that redirecting stdout works fine but not stderr? Stdout dosesn't seem to function when stderr fails?

Ls recognizes stdout but not stderr and I'm wondering how is that I can view what stderr is tagged to because to me it's obvious it's not the default '2'. Please help.
# 4  
Old 08-28-2008
What is your operating system?
What does the following give?
ls -lrt /dev/null

Check if this works?
ls -ld /usr /foo 2>/directory_where_u_have_permissions_to_write/err.txt
# 5  
Old 08-28-2008
Either you are using a csh derivative which doesn't understand the 2> redirection, or you mistyped it. In csh the redirection syntax is different. What happened in the last case was that the regular output was redirected to /dev/null and the error messages were not.
# 6  
Old 08-28-2008
Thanks ppl for the quick reply.

Sudhamacs, you answered before I got a chance to post the version but here is the information you requested..
Code:
je# uname -srp
FreeBSD 6.2-RELEASE i386
je#

Don't think that permissions is the issue here since ls isn't recognizing '2' as a valid operator. Hence ls with the d switch will fail.

Another note i should add is that when i hit up (history) i find that the system executes with a space.

ls -ld /usr /foo 1>/dev/null/
.. works on they system as ..
ls -ld /usr /foo 1 > /dev/null/

^^Not sure if this is relevant or not. Also, here's some additional information..


Code:
je# ls -l /dev/null
crw-rw-rw-  1 root  wheel    0,   6 Aug 28 14:35 /dev/null
je# ls -l /dev/st* /dev/fd
lrwxr-xr-x  1 root  wheel  4 Dec 31  1969 /dev/stderr -> fd/2
lrwxr-xr-x  1 root  wheel  4 Dec 31  1969 /dev/stdin -> fd/0
lrwxr-xr-x  1 root  wheel  4 Dec 31  1969 /dev/stdout -> fd/1

/dev/fd:
total 0
crw-rw-rw-  1 root  wheel    0,  18 Jul 27 21:37 0
crw-rw-rw-  1 root  wheel    0,  20 Jul 27 21:37 1
crw-rw-rw-  1 root  wheel    0,  22 Jul 27 21:37 2
je#


Last edited by phpfreak; 08-28-2008 at 04:03 PM..
# 7  
Old 08-28-2008
The % prompt is often indicative of csh, what does echo $SHELL say?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Confused about redirecting stderr

I know that mmmmm 2> error.txt will send the error message to the specified file instead of the screen. However, I have seen >&2 in some scripts, and I can't get it to do anything. A source said it sends stdout and stderr to a file. What file? Ubuntu 18.04.2; Xfce 4.12.3;... (11 Replies)
Discussion started by: Xubuntu56
11 Replies

2. Shell Programming and Scripting

Lost redirecting stderr & stdout to 3 files - one each plus combined

Hi folks I need/want to redirect output (stdout, stderr) from an exec call to separate files. One for stderr only and two(!) different (!) ones for the combined output of stderr and stdout. After some research and testing i got this so far : (( exec ${command} ${command_parameters} 3>&1... (6 Replies)
Discussion started by: MDominok
6 Replies

3. Shell Programming and Scripting

Preserve output order when redirecting stdout and stderr

Hi, I already searched through the forum and tried to find a answer for my problem but I didn't found a full working solution, thats way I start this new thread and hope, some can help out. I wonder that I'm not able to find a working solution for the following scenario: Working in bash I... (8 Replies)
Discussion started by: Boemm
8 Replies

4. Shell Programming and Scripting

Is there a way to tee stderr from a command that's redirecting error to a file?

I'm not a complete novice at unix but I'm not all that advanced either. I'm hoping that someone with a little more knowledge than myself has the answer I'm looking for. I'm writing a wrapper script that will be passed user commands from the cron... Ex: ./mywrapper.sh "/usr/bin/ps -ef |... (1 Reply)
Discussion started by: sumgi
1 Replies

5. Shell Programming and Scripting

Redirecting STDERR to a file from within a bash script

I am trying to redirect the output from stderr to a log file from within a bash script. the script is to long to add 2> $logfile to the end of each command. I have been trying to do it with the command exec 2> $logfile This mostly works. Unfortunately, when a read command requires that anything be... (5 Replies)
Discussion started by: vockleya
5 Replies

6. Shell Programming and Scripting

noob question about redirecting stderr

I dont know what I am doing wrong but I would like to redirect the stderr output to a file? the specific command is this time wget http://www.something.com/somefile.bin All I want to see is time's output which is stderr so I can see how long the file download took. I've tried redirecting... (2 Replies)
Discussion started by: trey85stang
2 Replies

7. Shell Programming and Scripting

Adding custom mesg. when redirecting "exec 2>stderr.err" ?

Doubt regarding using "exec" command to redirect the STDERR to a file. e.g I did it this way. mystage.sh #!/bin/sh exec 2>stage.err .... .... cat stage.err mv: cannot move `/root/stage' to a subdirectory of itself, `/root/stage_old/stage' ls: *.zDB: No such file or... (0 Replies)
Discussion started by: snurani
0 Replies

8. Shell Programming and Scripting

Redirecting STDERR message to STDOUT & file at same time

Friends I have to redirect STDERR messages both to screen and also capture the same in a file. 2 > &1 | tee file works but it also displays the non error messages to file, while i only need error messages. Can anyone help?? (10 Replies)
Discussion started by: vikashtulsiyan
10 Replies

9. Shell Programming and Scripting

Redirecting stderr while live

If I forget to set up stderr redirection on execution of a script, is there a way to set that redirection post-exec? In other words, if I have a script running and no errors are being logged... and then I remember that I forgot the 2>&1 on the script... can I turn it on after the fact? ...and... (1 Reply)
Discussion started by: jjinno
1 Replies

10. Shell Programming and Scripting

redirecting STDOUT & STDERR

In bash, I need to send the STDOUT and STDERR from a command to one file, and then just STDERR to another file. Doing one or the other using redirects is easy, but trying to do both at once is a bit tricky. Anyone have any ideas? (9 Replies)
Discussion started by: jshinaman
9 Replies
Login or Register to Ask a Question