ユーザを強制的にログアウトさせる

#!/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
view raw logout.sh hosted with ❤ by GitHub

ユーザが起動しているbashシェルのプロセスを強制的にkillするスクリプトです。結果的にユーザを強制的にログアウトさせることになります。ユーザが複数起動させているシェルを一度にkillしたいときなどに便利かもです。

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.