From DefCon Projects
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