Find the answer to your Linux question:
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 ...
  1. #1
    Linux Enthusiast meton_magis's Avatar
    Join Date
    Oct 2006
    Location
    arizona
    Posts
    665

    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

  2. #2
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    Can't you duplicate stderr to stdout?

  3. #3
    Linux Enthusiast meton_magis's Avatar
    Join Date
    Oct 2006
    Location
    arizona
    Posts
    665
    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

  4. #4
    Linux 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

  5. #5
    Linux Enthusiast meton_magis's Avatar
    Join Date
    Oct 2006
    Location
    arizona
    Posts
    665
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...