Skip to content

Instantly share code, notes, and snippets.

@loorlab
Created May 18, 2025 05:03
Show Gist options
  • Save loorlab/5b2ed2dd91c10bc3d625b167288012c7 to your computer and use it in GitHub Desktop.
Save loorlab/5b2ed2dd91c10bc3d625b167288012c7 to your computer and use it in GitHub Desktop.
Report Transients Bash WP .sh
#!/bin/bash
# Crear nombre de archivo con fecha actual
FECHA=$(date +"%Y-%m-%d_%H-%M")
ARCHIVO="transients_report_$FECHA.csv"
# Crear encabezado del CSV
echo "Nombre,Valor,Expira_en" > $ARCHIVO
# Obtener lista de transients en formato json
wp transient list --format=json | php -r '
$transients = json_decode(file_get_contents("php://stdin"), true);
foreach ($transients as $transient) {
$nombre = $transient["name"];
$valor = wp_cli_exec("wp transient get " . escapeshellarg($nombre) . " --format=json");
$valor_limpio = str_replace(",", ";", str_replace("\n", " ", $valor));
$expira = $transient["expiration"] ? date("Y-m-d H:i:s", $transient["expiration"]) : "No expira";
echo "$nombre,$valor_limpio,$expira\n";
}
function wp_cli_exec($command) {
exec($command, $output, $return_var);
return $return_var === 0 ? implode(" ", $output) : "N/A";
}
' >> $ARCHIVO
# Mostrar estadísticas generales
echo -e "\n--- REPORTE DE TRANSIENTS ---"
echo "Archivo creado: $ARCHIVO"
echo "Total de transients: $(wp transient list --format=count)"
echo "Tamaño del reporte: $(du -h $ARCHIVO | cut -f1)"
@loorlab
Copy link
Author

loorlab commented May 18, 2025

# cd ~
# nano transients-report.sh
# chmod +x transients-report.sh
# ./transients-report.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment