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:
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'"
# Quit cleanly
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.