login-notify.sh (555B) - raw


      1 #!/bin/sh
      2 # 2020 Oscar Benedito <oscar@oscarbenedito.com>
      3 # License: CC0 1.0 Universal License
      4 
      5 # Script that sends a notification when someone logs in through SSH to a
      6 # computer/server.
      7 
      8 # This scripts assumes there is an executable called "notify" in your PATH that
      9 # takes two arguments (the first one is the notification title and the second
     10 # one is the message).
     11 
     12 if [ "$PAM_TYPE" != "close_session" ]; then
     13   TITLE="SSH login: ${PAM_USER}@$(hostname)"
     14   MESSAGE="IP: ${PAM_RHOST}
     15 Date: $(TZ='Europe/Madrid' date)"
     16 
     17   notify "$TITLE" "$MESSAGE"
     18 fi