postgresql clean wal files script
#!/bin/bash
ARCHIVEDIR='/var/lib/postgresql/10/main/pg_wal'
LAST_BACKUP=$(ls -lto ${ARCHIVEDIR})
cd $ARCHIVEDIR
exec "/usr/bin/pg_archivecleanup" -d -n /var/lib/postgresql/10/main/pg_wal ${LAST_BACKUP} | find $ARCHIVEDIR -type f -mmin +5 -delete