To automate the summary generation, you can create a shell script that encapsulates the commands you've provided. Here’s a simple example of how to do this:
-
Create a Shell Script:
Create a new file calledgenerate_summary.sh:touch generate_summary.sh -
Edit the Script:
Open the file in a text editor and add the following content:#!/bin/bash # Define the output file OUTPUT_FILE="/home/labex/project/scan_summary.txt" # Write the summary header echo "Nmap Scan Summary" > "$OUTPUT_FILE" echo "----------------" >> "$OUTPUT_FILE" echo "Target: localhost (127.0.0.1)" >> "$OUTPUT_FILE" echo "Open ports:" >> "$OUTPUT_FILE" # Append open ports from scan results grep "open" /home/labex/project/scan_results.grep | grep -o "[0-9]*/open/tcp//[^/]*" >> "$OUTPUT_FILE" echo "Summary generated at $OUTPUT_FILE" -
Make the Script Executable:
Run the following command to make the script executable:chmod +x generate_summary.sh -
Run the Script:
Execute the script whenever you want to generate the summary:./generate_summary.sh
Automating with Cron (Optional):
If you want to run this script automatically at scheduled intervals, you can use cron:
-
Open the crontab editor:
crontab -e -
Add a line to schedule the script (e.g., to run every day at 2 AM):
0 2 * * * /path/to/generate_summary.sh
Summary:
This approach allows you to automate the summary generation process, making it easy to update the report without manual intervention. If you have further questions or need assistance, feel free to ask!
