我需要退出当前会话,我正在使用以下代码:
read -p "Do you want to start a new session? [Y/N] " usr_session
if [ "$usr_session" == "y" ] || [ "$usr_session" == "Y" ]; then
echo -e "`date`\t\t Exiting...\n You will need to login back...\n" >> $LOG_FILE
echo -e "Exiting...\n You will need to login back...\n"
sleep 5
curr_usr=`whoami`
pkill -9 -u $curr_usr
elif [ "$usr_session" == "n" ] || [ "usr_session" == "N" ]; then
echo -e "You are still in the same session.\n"
else
echo "Invalid input"
fi
有没有更好的方法来执行相同但更优雅的方式?我觉得杀死当前用户进程可能不安全。任何建议都非常感谢。
提前致谢。