Display status of instances in apache - Where to start

Hello,
I know this is not a simple question so I just need to know where to start for below project:
I am running under Ubuntu 18.04
What I'd like to see in apache page is to display status of particular process pids.

ps aux | grep keywords.txt

keywords.txt

word1
word2
word3
word4
word5

myscript

while read -r line
do
ps aux | grep $line
done <keywords.txt > report_to_apache

output:

root     28522  0.0  0.0   8820   752 pts/3    S+   13:24   0:00 grep word1.sh
root     28524  0.0  0.0   8820   780 pts/3    S+   13:24   0:00 grep word2.sh
root     28528  0.0  0.0   8820   756 pts/3    S+   13:24   0:00 grep word4.sh

output file gives only running processes.

Is it hard to make it visible like png files in apache as shown below:
Expected output in apache page:

status                                      process name
/var/www/html/green_flag.png  word1
/var/www/html/green_flag.png  word2
/var/www/html/red_flag.png     word3
/var/www/html/green_flag.png  word4
/var/www/html/red_flag.png      word5

Thanks in advance
Boris

Normally I would do this type of processing with PHP.

how about:

ps a -o args | grep -f keywords.txt

Hello Vgersh99,
It does not check each line in keywords file.
I mean "gives nothing"...
Kind regards
Boris

Hmmmm.... strange it should work...
Are you sure your keywords.txt file isn't in DOS format? Any weird characters etc?
Could you post the output of cat -vet keywords.txt using code tags....

Hello,
It gives:

word1$
word2$
word3$
word4$
word5$

when I type:

ps aux | grep word1 

it gives requested info...

this is not what I've suggested...

$ ps a -o args
COMMAND
/sbin/mingetty tty1
/sbin/mingetty tty2
/sbin/mingetty tty3
/sbin/mingetty tty4
/sbin/mingetty tty5
/sbin/mingetty tty6
ps a -o args
-bash
-bash

with /tmp/a:

tty1
tty2

running ps a -o args | grep -f /tmp/a produces:

/sbin/mingetty tty1
/sbin/mingetty tty2

--- Post updated at 10:10 PM ---
Hello Vgersh99,
It works as expected..
I also have wrote a very simple html to make it publish with png file.
Thank you so much again...

Kind regards
Boris

Actually, FYI, it is really easy to open a call to ps in PHP and process the output :slight_smile: Very easy and straight forward.

Nothing wrong with doing it in the shell, but don't forget that PHP is very easy to use and is great for these kinds of tasks.

1 Like