From DefCon Projects
Revision as of 11:33, 2 February 2025 by Webmaster (talk | contribs) (Created page with "Ich habe mehrere Server im Betrieb für die ich ein BASH-Skript benötigt habe das mich informiert wenn neue YUM Updates zu verfügung stehen. Ich möchte hier mit euch das BASH-Skript teilen: == Skript == <syntaxhighlight lang="c"> #!/bin/bash EMAIL="admin@example.com" STATE_FILE="/tmp/update_count.state" # Execute yum check-update and capture the output UPDATES=$(yum check-update --quiet 2>/dev/null) # Filter out empty lines and count the number of updates UPDATE...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Ich habe mehrere Server im Betrieb für die ich ein BASH-Skript benötigt habe das mich informiert wenn neue YUM Updates zu verfügung stehen. Ich möchte hier mit euch das BASH-Skript teilen:

Skript

#!/bin/bash
EMAIL="admin@example.com"
STATE_FILE="/tmp/update_count.state"

# Execute yum check-update and capture the output 
UPDATES=$(yum check-update --quiet 2>/dev/null)

# Filter out empty lines and count the number of updates 
UPDATES=$(echo "$UPDATES" | grep -v "^$") 
UPDATES_COUNT=$(echo -n "$UPDATES" | wc -l)

# Read the previous update count, if any
if [[ -f "$STATE_FILE" ]]; then
    PREVIOUS_COUNT=$(cat "$STATE_FILE")
else
    PREVIOUS_COUNT=0
fi

# Compare update counts
if [[ $UPDATES_COUNT -ne $PREVIOUS_COUNT ]]; then
    echo "$UPDATES" | mail -s "Updates for $(hostname): ${UPDATES_COUNT}" "$EMAIL"
    # Update the state file with the new count
    echo "$UPDATES_COUNT" > "$STATE_FILE"
fi
Cookies help us deliver our services. By using our services, you agree to our use of cookies.