Skip to content

Instantly share code, notes, and snippets.

@thonixx
Created August 25, 2013 15:59
Show Gist options
  • Save thonixx/6334662 to your computer and use it in GitHub Desktop.
Save thonixx/6334662 to your computer and use it in GitHub Desktop.
kicks other users out of their sessions with a message would kick root which comes from a defined destination
# kick function
# kicks other users out of their sessions with a message
# would kick root which comes from a defined destination
function kick() {
if [ -z "$1" ]
then
echo "need user"
return
fi
tty=$(w | grep -i "$1" | head -n 1 | awk '{print $2}')
$(mesg y)
echo -n "
You were kicked out of your session.
Sorry :/
" | write root "$tty" 2> /dev/null
$(ps faux | grep -i "$tty" | grep -v "grep" | awk '{print $2}' | xargs -n1 kill -9)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment