weekly lynis

This commit is contained in:
Eduardo David Paredes Vara
2025-12-05 00:55:03 +00:00
parent a651474dac
commit 80245f3227
2 changed files with 98 additions and 1 deletions

39
lynis/lynis-weekly Executable file
View File

@@ -0,0 +1,39 @@
#!/bin/bash
#
# Lynis Security Report - Weekly Cron Job
# Place this file in /etc/cron.weekly/
# Make it executable: chmod +x /etc/cron.weekly/lynis-weekly
#
# Script directory
SCRIPT_DIR="/opt/lynis-report"
# Python virtual environment
VENV_DIR="$SCRIPT_DIR/venv"
# Log file
LOG_FILE="/var/log/lynis-report.log"
# Change to script directory
cd "$SCRIPT_DIR" || {
echo "$(date): ERROR - Cannot change to directory $SCRIPT_DIR" >> "$LOG_FILE"
exit 1
}
# Log execution start
echo "$(date): Starting Lynis weekly report" >> "$LOG_FILE"
# Activate virtual environment and run the script
if [ -d "$VENV_DIR" ]; then
"$VENV_DIR/bin/python3" "$SCRIPT_DIR/lynis_report.py" >> "$LOG_FILE" 2>&1
else
# Fallback to system python3 if venv doesn't exist
python3 "$SCRIPT_DIR/lynis_report.py" >> "$LOG_FILE" 2>&1
fi
# Log execution result
if [ $? -eq 0 ]; then
echo "$(date): Lynis weekly report completed successfully" >> "$LOG_FILE"
else
echo "$(date): ERROR - Lynis weekly report failed with exit code $?" >> "$LOG_FILE"
fi