Check that fallback last access file exists

This commit is contained in:
Clemens Schwaighofer
2023-12-21 16:43:57 +09:00
parent 65b7a6ad43
commit 50e28c7cfd

View File

@@ -137,8 +137,15 @@ for ssh_group in ${ssh_groups[@]}; do
fi; fi;
# last try is user home .bash_logout # last try is user home .bash_logout
if ! [[ "${user_create_date_string}" =~ ^\d{4}-\d{2}-\{2} ]]; then if ! [[ "${user_create_date_string}" =~ ^\d{4}-\d{2}-\{2} ]]; then
home_dir=$(cat /etc/passwd | grep "${username}:" | cut -d ":" -f 6)"/.bash_logout"; # try logout or bash history
user_create_date_string=$(stat -c %Z "${home_dir}"); 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; fi;
# still no date -> set empty # still no date -> set empty
if ! [[ "${user_create_date_string}" =~ ^\d{4}-\d{2}-\{2} ]]; then if ! [[ "${user_create_date_string}" =~ ^\d{4}-\d{2}-\{2} ]]; then