Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, Can anyone tell me how to list the currently running processes via code a shell script. FYI i now about the top method in the terminal but i need ...
  1. #1
    Just Joined!
    Join Date
    Feb 2011
    Posts
    3

    Basic Shell Script Code

    Hi,

    Can anyone tell me how to list the currently running processes via code a shell script. FYI i now about the top method in the terminal but i need a way to have it via a shell script.

    Any help appreciated

    Thanks.

  2. #2
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    955
    ps ax lists all running processes briefly. ps aux gives the same listing with more information. You could pipe it through awk to strip out and rearrange the specific information you require about processes.
    "I'm just a little old lady; don't try to dazzle me with jargon!"

  3. #3
    Just Joined!
    Join Date
    Feb 2011
    Posts
    3
    Thanks. This is what i've got now so it outputs to a text file:

    echo $(ps aux) >>out

    It all works, but do you know if it is in any way possible to sort it so one process is on one line, making it more readable?

    Thanks again.
    Last edited by acwest; 02-06-2011 at 08:08 AM.

  4. #4
    Just Joined!
    Join Date
    Feb 2011
    Posts
    3
    Does anyone know how to sort the output to a text file so that it prints to the text file at 1 proccess per line? I know it probably simple but im very new to linux.

  5. #5
    Just Joined!
    Join Date
    Mar 2010
    Posts
    79
    You don't need to use echo and put the command in $()-syntax.
    Code:
    ps ax > out.txt
    That works here (while your code gives output like described by you).

    If you use > it will overwrite existing content.
    If you use >> it will append to existing content.

Posting Permissions

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