Note: The Listed platform will permanently shut down December 31, 2026. Your data published on Listed will still be available in your personal Standard Notes account. Learn more

๐Ÿ”ง HMAS TIP

๐Ÿ”ง Hacker-Style Linux System Reporter using HMAS API


โœ… Overview

This project provides a Bash script to send system status reports.

It avoids input errors by using the send= or share= endpoints, and it provides

flexibility to send messages either to another user (via API key) or to an email address.


๐Ÿ“„ Bash Script: sys_report.sh

#!/bin/bash

# === CONFIGURATION ===
API_KEY="your_api_key"
API_URL="https://carlostkd.ch/hmas/api.php"
RECIPIENT_KEY="recipient_api_key"  # Can be your own API key too
EMAIL_RECIPIENT="admin@example.com"  # Optional: for `share=`
USE_EMAIL=0  # Set to 1 to use email sharing, 0 to use API key

# === COLLECT SYSTEM INFO ===
UPTIME=$(uptime -p)
DISK=$(df -h / | awk 'NR==2 {print $5 " used on " $6}')
MEMORY=$(free -h | awk '/Mem:/ {print $3 "/" $2}')
USERS=$(who | wc -l)
HOST=$(hostname)
TIME=$(date)

# === FORMAT MESSAGE ===
MESSAGE="System Report from $HOST on $TIME

"
MESSAGE+="โ€ข Uptime: $UPTIME
"
MESSAGE+="โ€ข Disk Usage: $DISK
"
MESSAGE+="โ€ข Memory: $MEMORY
"
MESSAGE+="โ€ข Logged-in Users: $USERS"

# === URL-ENCODE MESSAGE ===
ENCODED_MSG=$(echo -e "$MESSAGE" | jq -sRr @uri)

# === SEND VIA API ===
if [ "$USE_EMAIL" -eq 1 ]; then
    echo "[+] Sending report via email to $EMAIL_RECIPIENT..."
    curl -G "$API_URL" \
        --data-urlencode "share=$EMAIL_RECIPIENT" \
        --data-urlencode "msg=$ENCODED_MSG" \
        --data-urlencode "apikey=$API_KEY"
else
    echo "[+] Sending encrypted message to $RECIPIENT_KEY..."
    curl -G "$API_URL" \
        --data-urlencode "send=$ENCODED_MSG" \
        --data-urlencode "rec=$RECIPIENT_KEY" \
        --data-urlencode "selfdestruct=1" \
        --data-urlencode "apikey=$API_KEY"
fi

โš™๏ธ How It Works

  • Gathers: uptime, disk usage, memory use, login count.
  • Formats: Multi-line string report.
  • Encodes: URL-encodes full message using jq to prevent API validation errors.
  • Sends: Either:
    • Via send=: Encrypted, self-destructing message to another user.
    • Via share=: Email message to a recipient.

๐Ÿงช Requirements

  • jq (for URL encoding): bash sudo apt install jq

๐Ÿ’ก Example Use Cases

  • ๐Ÿ• Cronjob: Auto-send system reports every hour:
    and you dont need to set any email configurations

    0 * * * * /home/user/scripts/sys_report.sh
    
  • ๐Ÿ‘จโ€๐Ÿ’ป Manual Use:

    ./sys_report.sh
    
  • ๐Ÿ“ฌ Use for Monitoring:
    Trigger alerts for high disk usage or login activity via custom logic.

  • ๐Ÿ” Secure Messaging:
    Message disappears after read using selfdestruct=1.


โœ… Create by HAMAS Team


You'll only receive email when they publish something new.

More from Carlostkd โœ…
All posts