From 50e28c7cfde4b5d7d0c5417dfdd4d7ab88196fb7 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Thu, 21 Dec 2023 16:43:57 +0900 Subject: [PATCH] Check that fallback last access file exists --- bin/check_last_login.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bin/check_last_login.sh b/bin/check_last_login.sh index cff518f..1551aa7 100755 --- a/bin/check_last_login.sh +++ b/bin/check_last_login.sh @@ -137,8 +137,15 @@ for ssh_group in ${ssh_groups[@]}; do fi; # last try is user home .bash_logout if ! [[ "${user_create_date_string}" =~ ^\d{4}-\d{2}-\{2} ]]; then - home_dir=$(cat /etc/passwd | grep "${username}:" | cut -d ":" -f 6)"/.bash_logout"; - user_create_date_string=$(stat -c %Z "${home_dir}"); + # try logout or bash history + home_dir_bl=$(cat /etc/passwd | grep "${username}:" | cut -d ":" -f 6)"/.bash_logout"; + home_dir_bh=$(cat /etc/passwd | grep "${username}:" | cut -d ":" -f 6)"/.bash_history"; + # check that this file exists + if [ -f "${home_dir_bl}" ]; then + user_create_date_string=$(stat -c %Z "${home_dir_bl}"); + elif [ -f "${home_dir_bh}" ]; then + user_create_date_string=$(stat -c %Z "${home_dir_bh}"); + fi; fi; # still no date -> set empty if ! [[ "${user_create_date_string}" =~ ^\d{4}-\d{2}-\{2} ]]; then