Monday, April 29, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 664  / 3 Years ago, tue, september 7, 2021, 8:23:49

I am interested in finding what applications/scripts are executed by each linux user.


I can find the number of jobs run by a specific user with the following command


ps -u <USERNAME> -U <USERNAME>

However it shows the jobs of a specific provided user whereas I want it for all users or all local users.


E.g. the following command count the number of jobs by each user


ps -eo user=|sort|uniq -c

I want a similar command but i want to see all the processes run by a user. Thanks.


@update E.g.


Uname    PID   CMD    
user1 1010 systemd
user1 1011 sshd
user1 1012 bash
user1 1013 ps
user2 1020 systemd
user2 1021 sshd
user2 1022 bash
user2 1023 ps
user2 1024 tux
user2 1025 python
user2 1026 python
.......
.......
.......

More From » command-line

 Answers
5

You were almost there, you only need a loop over the user names.
Write a shell script, say, ps_users.sh like


 #!/bin/bash

NUSERPROC=$(ps -eo user=|sort|uniq)

for user in ${NUSERPROC} ; do
echo "========= ${user} ========="
ps -u ${user} -U ${user}
done

(of course, do not include the line numbers) and then run sh ./ps_users.sh.
Adapt the contents of the loop to cater your needs.


[#1857] Thursday, September 9, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
damomnning

Total Points: 422
Total Questions: 90
Total Answers: 106

Location: Mali
Member since Thu, Aug 13, 2020
4 Years ago
;