Results 1 to 5 of 5
I'm having a problem at work. We use AIX machine (yuck), but i'm hoping that someone here can help out, because i don't know where to find AIX help.
We ...
- 08-13-2008 #1
Problem with using stream editors with stderr
I'm having a problem at work. We use AIX machine (yuck), but i'm hoping that someone here can help out, because i don't know where to find AIX help.
We will often fill filesystems with log files, and it's my job to delete them. However, you can't delete a file if it's being used by a process, because it doesn't free the space used by the file, just removes the file from sight (bad thing basically.) easy enough to solve, just run fuser on the file to make sure it's free. Well me being the computer nerd that i am, i like to try to do stuff with 1 command. I tried this:
ls -l | awk '$6 ~ "Jan|Feb|Mar|Apr" && $8 == "2007" {print "fuser "$9}' | ksh | sed "s/:/ /g" | awk '$2 == "" {print "rm " $1}' | ksh
fuser prints out stuff like this
file1: PID_USING_FILE
file2: <---- no lock on file, safe for deletion, so $2 is empty
file3: PID_USING_FILE
HOWEVER, the file1:, file2: are printed to stderr, not stdout. sed and awk wont work on them
Does anyone know how to solve my problem??
help me obi wan kinobe, your my only hope.New to the internet, technical forums, or the hacker / open source community??
Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html
RHCE for RHEL version 5
RHCT for RHEL version 4
- 08-13-2008 #2Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
Can't you duplicate stderr to stdout?
- 08-14-2008 #3
I don't know, can you?
New to the internet, technical forums, or the hacker / open source community??
Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html
RHCE for RHEL version 5
RHCT for RHEL version 4
- 08-14-2008 #4Linux User
- Join Date
- Jun 2007
- Posts
- 318
To redirect stderr to stdout use '2>&1'. '2' is the channel no. for stderr and 1 is the channel no. for stdout. Your command should look like:
ls -l | awk '$6 ~ "Jan|Feb|Mar|Apr" && $8 == "2007" {print "fuser "$9}' | ksh 2>&1 | sed "s/:/ /g" | awk '$2 == "" {print "rm " $1}' | ksh
- 08-16-2008 #5
thanks m8, that helps a lot.
New to the internet, technical forums, or the hacker / open source community??
Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html
RHCE for RHEL version 5
RHCT for RHEL version 4


Reply With Quote