Created
May 18, 2025 05:03
-
-
Save loorlab/5b2ed2dd91c10bc3d625b167288012c7 to your computer and use it in GitHub Desktop.
Report Transients Bash WP .sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.