Skip to content

Instantly share code, notes, and snippets.

@aripalo
Created November 25, 2016 18:35
Show Gist options
  • Save aripalo/a6887ed9baca56a2e834a31fdc41f357 to your computer and use it in GitHub Desktop.
Save aripalo/a6887ed9baca56a2e834a31fdc41f357 to your computer and use it in GitHub Desktop.
macOS: Notify when successful SSH login
#!/bin/bash
machine_hostname=$(hostname -s)
while read line; do
if [[ $line == *"$machine_hostname sshd:"* ]]
then
user=$(echo $line | sed -e 's/.*sshd:\(.*\)\[priv.*/\1/' | tr -d '[:space:]')
process=$(echo $line | sed -e 's/.*USER_PROCESS:\(.*\)tty.*/\1/' | tr -d '[:space:]')
logger -p 5 -t "ssh-login-notify" -s "ssh-login-notify: user \"$user\" (process: \"$process\")"
osascript -e "display notification \"user: $user\nprocess: $process\" with title \"SSH Login: $user\""
fi
done
@aripalo
Copy link
Author

aripalo commented Nov 25, 2016

Usage:

chmod +x ssh-login-notify.sh.sh
tail -F /var/log/system.log | ./ssh-login-notify.sh.sh

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment