login-notify.sh (1190B) - raw


      1 #!/bin/sh
      2 # Copyright (C) 2020 Oscar Benedito <oscar@oscarbenedito.com>
      3 #
      4 # This program is free software: you can redistribute it and/or modify
      5 # it under the terms of the GNU Affero General Public License as
      6 # published by the Free Software Foundation, either version 3 of the
      7 # License, or (at your option) any later version.
      8 #
      9 # This program is distributed in the hope that it will be useful,
     10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 # GNU Affero General Public License for more details.
     13 #
     14 # You should have received a copy of the GNU Affero General Public License
     15 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
     16 
     17 # Script that sends a notification when someone logs in through SSH to a
     18 # computer/server.
     19 
     20 # This scripts assumes there is an executable called "notify" in your PATH that
     21 # takes two arguments (the first one is the notification title and the second
     22 # one is the message).
     23 
     24 if [ "$PAM_TYPE" != "close_session" ]; then
     25   TITLE="SSH login: ${PAM_USER}@$(hostname)"
     26   MESSAGE="IP: ${PAM_RHOST}
     27 Date: $(TZ='Europe/Madrid' date)"
     28 
     29   notify "$TITLE" "$MESSAGE"
     30 fi