How to automatically export OpenVAS reports after each scan to a folder (e.g., /var/lib/openvas/reports)?

Hello, I have a scheduled daily scan task, and I would like to automatically export this scan to a specific folder (e.g., /var/lib/openvas/reports) in JSON format.

I tried using this script, but gvm-cli does not recognize the syntax (–gmp-username “admin” --gmp-password “your_password”), and it also does not run as root.

#!/bin/bash

# Variables
TIMESTAMP=$(date +%Y%m%d%H%M)
REPORT_ID="<ID_SCAN>"  
OUTPUT_DIR="/var/lib/openvas/reports/"
OUTPUT_FILE="$OUTPUT_DIR/report_$TIMESTAMP.json"

# Export du rapport
gvm-cli socket --gmp-username "admin" --gmp-password "your_password" --xml \
"<get_reports report_id='$REPORT_ID' format_id='c1645568-627a-11e3-a660-406186ea4fc5'/>" > $OUTPUT_FILE

echo "Rapport exporté : $OUTPUT_FILE"

Do you have a solution? Thank you very much.

1 Like

Firstly, using double quotes is not the same as single quotes in Bash. Since you are not using environment variables for your passwords, you should use single quotes to preserve all characters as literal, with no special interpretation. If you have $ char in your password, using doubles quotes will treat it like a variable. Secondly, you can see the examples here for best practices on nesting " by escaping them.

Otherwise, I cannot see the error. If you post the actual error output it helps a lot.

1 Like