Reputation: 1723
I must create a Shell
that when a user logs in, it will print on the terminal from which the connection was made how many users are logged in an their number of processes.
The second part ( the one with processes ) was easy, thanks you the following command
ps hax -o user | sort | uniq -c
But I can't go any further. I don't know how to automatically launch this script for every user, and even more, how to write on their terminal. ( I fount commands like msg
, write
but all require me to insert the username)
Upvotes: 0
Views: 1887
Reputation: 454
Your command ps hax -o user | sort | uniq -c
does not show count of processes of logged in users but of every user (including system accounts) not necessarily currently logged in.
List of only logged in users can be get with who
command.
To get count of processed per logged in user one can try:
for u in `who -u | cut -f1 -d' ' | sort -u`; do echo -n "$u "; ps hx -u $u | wc -l; done;
Message displayed on users terminal only at login time is set in /etc/motd
test file. This is static file. What you need is dynamically generated motd
file. This can be achieved with update-motd
.
On Ubuntu/Debian update-motd
configuration scripts can be found in /etc/update-motd.d/
I'm not sure if similar feature is available on RedHat like systems but you can search for update-motd
or dynamic motd.
Upvotes: 2
Reputation: 121
If you want the message to appear only each time the user opens the terminal, you can edit /etc/bash.bashrc and include the .sh script from there. This file basically contains commands that get executed every time a terminal is opened.
Upvotes: 0