Results 1 to 7 of 7

Thread: send output of running process to other command

  1. #1
    Join Date
    Aug 2006
    Location
    North East England
    Beans
    576
    Distro
    Ubuntu

    send output of running process to other command

    Hi there, I am wondering if it is possible to pipe the output of a command while it is still running through grep to search for certain lines.

    Here's the specifics:

    I am running autopsy with remote hosts and ports specified using the command line, for example:
    Code:
    ./autopsy -p 9001 192.168.1.100
    When it activates, it ties up terminal until I use CTRL+C to terminate it. I have tried the following:
    Code:
    ./autopsy -p 9001 192.168.1.100 | grep [search phrase] >> info.txt
    to send the output to a file, but this doesn't do this until after the process is terminated, which is too late.

    Any ideas?

    Cheers

    Ben

  2. #2
    Join Date
    Jun 2006
    Location
    $ pwd _
    Beans
    3,999
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: send output of running process to other command

    Why not redirect the output of the running process to a file and then grep on the file?

    Code:
    ./autopsy -p 9001 192.168.1.100 > autospy.log 2>&1 &
    Code:
    grep [search phrase] autospy.log

  3. #3
    Join Date
    Aug 2006
    Location
    North East England
    Beans
    576
    Distro
    Ubuntu

    Re: send output of running process to other command

    Quote Originally Posted by kpkeerthi View Post
    Why not redirect the output of the running process to a file and then grep on the file?

    Code:
    ./autopsy -p 9001 192.168.1.100 > autospy.log 2>&1 &
    Code:
    grep [search phrase] autospy.log
    Outstanding, that did the trick! Thanks!

    Out of interest, what does the 2>&1 do?

    Thanks

    Ben
    Last edited by benfindlay; June 4th, 2009 at 04:11 PM. Reason: typo

  4. #4
    Join Date
    Oct 2008
    Beans
    561

    Re: send output of running process to other command

    just run the process in the background,
    add an '&' suffix to the command
    Check out my little app. Tnote

  5. #5
    Join Date
    Aug 2006
    Location
    North East England
    Beans
    576
    Distro
    Ubuntu

    Re: send output of running process to other command

    A normal & doesn't work it seems. From what I can tell, the process isnt really meant to be run in background.

    Putting an & between the ./autopsy and | grep seems to prevent the pipe from working, and if it is moved to the end of the line, grep won't carry out the instructions until the application is terminated. This is a problem as autopsy generates a unique URL for the remote hosts to connect to each time it is run, meaning that I can't get that URL until after it terminates (and the next time it generates a new one).

  6. #6
    Join Date
    Jun 2006
    Location
    $ pwd _
    Beans
    3,999
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: send output of running process to other command

    Quote Originally Posted by benfindlay View Post
    Outstanding, that did the trick! Thanks

    Out of interest, what does the 2>&1 do?

    Thanks

    Ben
    2 is the file descriptor for standard error and 1, standard output.
    2>&1 sends 2 (the errors) to the same place where 1 (the output) is also sent, in our case to autospy.log file.

  7. #7
    Join Date
    Aug 2006
    Location
    North East England
    Beans
    576
    Distro
    Ubuntu

    Re: send output of running process to other command

    Excellent, thanks again!

    Ben

Tags for this Thread

Bookmarks

Posting Permissions

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