Skip to content

Instantly share code, notes, and snippets.

@hongkongkiwi
Last active January 13, 2016 12:41
Show Gist options
  • Save hongkongkiwi/2595b145e0b2ee038ca8 to your computer and use it in GitHub Desktop.
Save hongkongkiwi/2595b145e0b2ee038ca8 to your computer and use it in GitHub Desktop.
Simple bash script to logout a user from the terminal.
#!/bin/bash
USERNAME=$1
if [[ "$USERNAME" == "" ]]; then
echo "ERROR: No username specified!"
echo "USAGE: $0 <username>"
exit 1
fi
pn=`ps awwwwux | awk '/${USERNAME}/ && /loginwind[o]w/ { print $2 }'`
if [[ $pn != "" ]]; then
sudo kill -9 $pn
echo "$USERNAME is logged off"
else
echo "$USERNAME is not logged in"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment