Linux Login Notification
The following steps will create a script that will run anytime a user profile is loaded/logged in. The script will send a notification to a webhook.
Create the script file
sudo nano /usr/local/bin/login_webhook.sh
Save the following script
#!/bin/bash
# URL of the webhook
WEBHOOK_URL="ENTER YOUR WEBHOOK URL HERE"
# Get the username, hostname, and current date/time
USERNAME=$(whoami)
HOSTNAME=$(hostname)
DATETIME=$(date +"%Y-%m-%d %H:%M:%S")
# Construct JSON data
DATA=$(printf '{"content": "%s - %s has logged into %s"}' "$DATETIME" "$USERNAME" "$HOSTNAME")
# Debug output
echo "Sending data: $DATA" > /tmp/webhook_debug.log
echo "Using URL: $WEBHOOK_URL" >> /tmp/webhook_debug.log
echo "Content-Type: application/json" >> /tmp/webhook_debug.log
# Send POST request
curl -X POST -H "Content-Type: application/json" -d "$DATA" "$WEBHOOK_URL" >> /tmp/webhook_debug.log 2>&1
Set proper permissions to the script
sudo chmod +x /usr/local/bin/login_webhook.sh
Modify the global profile
sudo nano /etc/profile
Add the following line to the end of the file
/usr/local/bin/login_webhook.sh