I have a bunch of undisciplined users with mail accounts on a server of mine. They never empty their trash or junk folders and the number of files rise to infinity.
I am creating a Bash script to erase those files periodically using cron.
I have done this:
- create a txt file with a list of directories I want to erase;
- create a script that will read line by line, every directory and erase everything from
Example of txt file:
~/mail/.Junk/cur ~/mail/.Junk/new ~/mail/.Trash/cur ~/mail/. Trash/new ~/firstname.lastname@example.org/.Junk/cur ~/email@example.com/.Junk/new ~/firstname.lastname@example.org/.Trash/cur ~/email@example.com/.Trash/new ~/firstname.lastname@example.org/.Junk/cur ~/mail/. email@example.com/.Junk/new ~/mail/. firstname.lastname@example.org/.Trash/cur ~/mail/. email@example.com/.Trash/new
I am at the first phase of the script creation where I test if I can access the directories and list their contents.
So I have this script:
#!/bin/bash while read line do ls $line done < ~/directories.txt
When I run the script I get the following error:
ls: cannot access ~/firstname.lastname@example.org/.Junk/new/: No such file or directory
for all directories but If I type
it works fine.