Skip to content

Instantly share code, notes, and snippets.

@ix4
Forked from AlBichutsky/login-script.sh
Last active November 22, 2021 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ix4/86b3d589cb7a736c083285cb4f9c3799 to your computer and use it in GitHub Desktop.
Save ix4/86b3d589cb7a736c083285cb4f9c3799 to your computer and use it in GitHub Desktop.
Auto-Translated from Russian
#!/bin/bash
# disable the output of messages to the console if users log in under non-existent names
exec 2>/dev/null
# name of the group that is allowed access on weekends
group="admin"
# check if the user $ PAM_USER belongs to the admin group: no - 0, yes -1
check_group=$(id -Gn $PAM_USER | grep -w $group | awk '{print $2}' | wc -l)
# check if the current day is Saturday: no - 0, yes - 1
check_saturday=$((date +%u) | grep "6" | wc -l)
# check if the current day is Sunday: no - 0, yes - 1
check_monday=$((date +%u) | grep "7" | wc -l)
# checking if the current day is a holiday (parse the /etc/security/holidays.conf file): no - 0, yes - 1
check_holidays=$(cat /etc/security/holidays.conf | awk '/^holiday/{print $2}' | grep $(date +%d-%m-%y) | wc -l)
# if the user does not belong to the admin group and today is Saturday / Sunday / holiday
if [[ $check_group -eq 0 ]] && [[ $check_saturday -eq 1 || $check_monday -eq 1 || $check_holidays -eq 1 ]]
then
# then display the message
echo "Warning! $ PAM_USER limited access to server on weekends / holidays!"
echo "Today: $ (date +% d-% m-% y), day of the week: $ (date +% A)"
# and start the timer cycle before the start of the working day
until [[ $check_saturday -eq 0 && $check_monday -eq 0 && $check_holidays -eq 0 ]]
do
# the user will not be able to enter the password, after 30 seconds there will be a return to entering the login, and then re-verification
sleep 30
done
else
exit 0 # if the user of the group admin is logged in - end the script execution and continue authentication
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment