Hello,
I am currently writing a bash script that checks if a user has logged in more than once, by checking the output of 'ps x' The output is processed so only two columns of data are available - the PID and the username. If the script finds that two users (with the same username) are logged in, both the users PIDs should be passed to the 'kill' command so they both get disconnceted. I'm slowly getting there:
Code:
#!/bin/bash
declare users=`ps x | grep priv | tr -s " " | cut -f 1,6 -d ' '`
# Main Loop
# if [ $user1 == $user2 ]
# then echo "Match found, disconnecting user '$user1'"
# fi
echo $users
# Quit cleanly
exit
Right now, the script just prints out the current users and their PIDs. Unfortunately I don't know how to go any further due to my lack of experience / knowledge. Any help on how to compare every username to every other username, and extract PIDs if/when matches are found would be highly appreciated.
PS I am aware that there is a way to limit concurrent logins, and this is not what I want. I want both users to be D/Cd.
Recent comments
8 hours 25 min ago
13 hours 30 min ago
17 hours 55 min ago
19 hours 44 min ago
1 day 9 hours ago
1 day 10 hours ago
1 day 14 hours ago
1 day 21 hours ago
1 day 22 hours ago
1 day 23 hours ago