I modified this bash to auto clean Trash / Spam folder which might take too much space. But it does not seem to work. Can you please check:
#!/usr/bin/bash
#run this so cron job has environment variable
export hestia='/usr/local/hestia'
#can't force everyone to use the same folders, so catch both variants
declare -a dcfolders=( "Trash" "Spam" )
/usr/local/hestia/bin/v-list-users plain | cut -f1 | sort | while read -r vuser ; do
/usr/local/hestia/bin/v-list-mail-domains $vuser plain | cut -f1 | sort | while read -r vdomain ; do
/usr/local/hestia/bin/v-list-mail-accounts $vuser $vdomain plain | cut -f1 | sort | while read -r vaccount ; do
for dcfolder in "${dcfolders[@]}"
do
if /usr/bin/doveadm mailbox list -u [email protected]$vdomain | grep "^${dcfolder}$";
then
echo "[email protected]$vdomain $dcfolder"
/usr/bin/doveadm -v expunge -u [email protected]$vdomain mailbox "$dcfolder" savedbefore 30d
fi
done
done
done
done
But why cannot I get it run via cron you think?. Cron log says:
/usr/local/hestia/bin/v-list-users: line 108: /data/users/usernamehere/user.conf: No such file or directory
Nobody willing to help
This is actually working on a plesk server of mine.
I have not ported it yet
The full script is gatbage and I should refactor it with awk
#!/bin/bash
df -h | grep dev #borrado ficheros muy grandes de hace mĂĄs de 1 semana
tamano0="+20M"
tiempo0="+7" #borrado ficheros muy grandes de hace mĂĄs de 1 mes
tamano1="+16M"
tiempo1="+30" #borrado ficheros muy grandes de hace mĂĄs de 3 meses
tamano2="+12M"
tiempo2="+90" #borrado de ficheros grandes de hace mĂĄs de 6 meses
tamano3="+8M"
tiempo3="+180" #borrado de ficheros grandes de hace mås de 1 año
tamano4="+4M"
tiempo4="+360" #borrado de ficheros grandes de hace mĂĄs de 18 meses
tamano5="+2M"
tiempo5="+540" #borrado de ficheros grandes de hace mås de 2 años
tamano6="+1M"
tiempo6="+720" #borrado de ficheros medianos de hace mås de 3 años
tamano7="+500k"
tiempo7="+1050"
tamano8="+300k"
tiempo8="+1400"
tamano9="+200k"
tiempo9="+1750"
You can also do this in dovecot config by adding eg.
autoexpunge=30d
to the namespace config for each mailbox, if you want to do it over the whole server.
WRT your query about the script not working, cron has a different set of environment variables available, to a normal interactive login.
If youâre curious to see then set a cron job to run env and output to a file.
* * * * * /usr/bin/env > ~/cronenv.txt
Then remove it once youâve got the results.
Youâll probably find youâll have to add
HESTIA=/usr/local/hestia
to your script, so it can locate those files in the data directory