#!/bin/bash # pam_script session open script. # This script is executed by root when a new session is opened. echo "[$PAM_TYPE] Creating new session for $PAM_USER." min_uid=234299000 [ $(id -u $PAM_USER) -gt $min_uid ] || exit 0 session_counter=/tmp/$PAM_USER.sessioncount num_user_proc=$(ps aux|grep $PAM_USER -c|grep -v grep) if [ $num_user_proc -eq 0 ] then # no running session, write 1 since we are creating a new session. echo "1" > $session_counter else # running session, increment current_count=$(cat $session_counter) echo "$(($current_count+1))" > $session_counter fi