• The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Resolved In Schedule script cant find addional file who is needed

hintzsche

New Pleskian
Hello,

i created a script that deletes all emails older than 90 days for my server. Then i created a schedule in schedules and tasks and entered the /script.sh in run a command. When i test run the schedule it tells me that the script cant find the file where the user data is stored. The user data file is in the same direcotry as the script file. Where is my mistake? Thanks for your help.
 
Then i created a schedule in schedules and tasks and entered the /script.sh in run a command. When i test run the schedule it tells me that the script cant find the file where the user data is stored. The user data file is in the same direcotry as the script file. Where is my mistake? Thanks for your help.
You'll probably need to specify the full directory path.

Also, as an alternative, you can use the doveadm utility (if you have Dovecot installed).

For example, you can run the following doveadm command to delete messages from the Inbox folder of [email protected] which are older than 90 days.
Bash:
doveadm expunge -u "[email protected]" mailbox INBOX before 90d

Or to delete messages for all users on all mailbox folders older than 90 day you can use:
Bash:
doveadm expunge -A mailbox '*' before 90d

More info on doveadm expunge: Tools/Doveadm/Expunge - Dovecot Wiki
 
the mbox.txt is in the same directory as the script.sh

the script is:

#!/bin/bash
for mailbox in $(cat mbox.txt); do
doveadm expunge -u $mailbox mailbox 'INBOX' before 90d
done

I know doveadm this is what the script is using. but i want to use the mbox.txt file cause then i just have to change the txt file if I want to add more email adresses. what do you mean with the exact path both files are in the root directory /. if i chane mbox.txt to /mbox.txt or ./mbox.txt nothing changes. thats not the problem i guess.
 
Also, you can use the -F option on the doveadm expunge utility to specify a file with users. Which would eliminate the need for a for loop. Leaving you with a nice onliner as a script ;)

Bash:
doveadm expunge -F "/mbox.txt" mailbox 'INBOX' before 90d
(I have not tested this, but according this the documentation this should work)
 
Thank you very much. But when i use the command without a script i have to write a comand for every single folder? I mean i want to delete emails in every folder exept archive.
 
But when i use the command without a script i have to write a comand for every single folder?
Sorry, I don't quite understand what you're saying. Why would you have to write a command for every single folder?
 
Last edited:
i dont want to, i have to when i just use the doveadm command. Because doveadm expunge -u [email protected] mailbox INBOX before 90d is one comand and one folder. That would be a very long list of commands for every user and a folder In Schedules and tasks. Therefore i need a script to specify Folders and an extra file to easely change or add users.
 
Perhaps I misunderstand what you're saying. Let me reiterate. Your opening question was about getting your code to work when running a cronjob. You can solve that by wrapping the file path in your code in double quotes. Like $(cat "\mbox.txt") instead of $(cat mbox.txt).

My previous post was merely a suggestion on how to shorten your code with the same result. Because this code:
Bash:
for mailbox in $(cat "\mbox.txt"); do
    doveadm expunge -u $mailbox mailbox INBOX before 90d
done

does the same as this code (but it is shorter).
Bash:
doveadm expunge -F "/mbox.txt" mailbox INBOX before 90d

Obviously both get the job done just fine.
 
The actual script is longer. i shortened it because it is not neccesarry for understanding the problem. So i have to change the script from

#!/bin/bash
for mailbox in $(cat mbox.txt); do
doveadm expunge -u $mailbox mailbox 'INBOX' before 90d
" " mailbox.SEND' before 90d
" ".DRAFT before 90d
done

to

#/bin/bash
do
doveadm expunge -F "/mbox.txt" mailbox 'INBOX' before 90d
doveadm expunge -F "/mbox.txt" mailbox mailbox.SEND before 90d
so on and so forth
done

have i understand that correct? Sorry i thought you mean i shall use this command instead of the script :)
 
Ohw, I see. Yes, in that case my suggestion does not help you much. You still need to use the for loop because of all the mailbox folders.
 
Back
Top