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 | |
##Force to logout user | |
if [ $# -ne 1 ];then | |
echo "Usage: $0 [username]" | |
exit 1 | |
fi | |
#Checking user | |
usr=$(who | grep $1 | wc -l) | |
if [ $usr -eq 0 ];then | |
echo "No such user!" | |
exit 2 | |
fi | |
#Kill user's bash process | |
shell_pid=$(ps aux | grep $1 | awk '$NF=="-bash" {print $2}') | |
kill -9 $shell_pid |
ユーザが起動しているbashシェルのプロセスを強制的にkillするスクリプトです。結果的にユーザを強制的にログアウトさせることになります。ユーザが複数起動させているシェルを一度にkillしたいときなどに便利かもです。