Last active
January 13, 2016 12:41
-
-
Save hongkongkiwi/2595b145e0b2ee038ca8 to your computer and use it in GitHub Desktop.
Simple bash script to logout a user from the terminal.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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