Delete old files automatically using "scheduled jobs"

  • Hi,


    I'm relatively new to OMV but have managed to use these forums to answer most of the questions I've had so far. Despite a lot of attempts, I simply can't get a scheduled job working that will delete files older than 'x number of days'. My setup is a HP N54L with OMV 4.1.11 (Arrakis).


    I have an IP security camera sending photos and short video clips to a shared folder on the server. Obviously these files build up over time and are of little use once they are a few days old. Currently I delete these files manually every so often. I have searched google and these forums for a solution, so far I have tried creating a scheduled job using the following commands:


    find /sharedfolders/C********e -mtime +1 -exec rm {} \;
    find /sharedfolders/C********e -mtime +1 -type f -delete


    The above commands both returned errors stating that the folder location could not be found. Then I tried:


    find /srv/dev-disk-by-label-S*****E/C******Y -type f -mtime +1 -exec rm {} \;
    find /srv/dev-disk-by-label-S*****E/C******Y -mtime +1 -type f -delete


    Then I noticed I had not been adding a '/' to the end of my file path, so tried the following two variants:


    find /srv/dev-disk-by-label-S*******E/C******Y/ -type f -mtime +1 -exec rm {} \;
    find /srv/dev-disk-by-label-S*******E/C******Y/ -mtime +1 -type f -delete


    All of the above four commands ran without any errors, however when I test them by running the command (execute cron job) all I see is a brief "please wait" dialogue and ultimately no files are deleted. All scheduled jobs are run using the root user.


    I think the issue is probably related to my lack of understanding about Linux folder structures, but I've been unable to resolve this through searching alone.


    Any help that forum members could provide would be most appreciated.


    Thanks

  • Hi Stramm,


    Thanks for the info. It's a little over my head though.


    I get that I need to use the full folder path. Would I use the code you have written in the cron job command itself, or do I need to use it elsewhere in order to find the string for the full folder path which can then be used in the cron job command?


    Thanks Again

  • Oh, I'm sorry...
    The which command you use on the command line. For the find command it spits out the above path. That path including the command you use in your crontab and not just the plain command


    In the end you have something like that


    /usr/bin/find /srv/dev-disk-by-label-S*******E/C******Y/ -mtime +1 -type f -delete


    Use which followed by the command in question to get the full path to the command (as said on the command line).


    The path to rm is /bin/rm

  • Thanks again Stramm. I think I understand now.


    Unfortunately i tried the code you suggested, the result was the same (I see is a brief "please wait" dialogue and ultimately no files are deleted, no errors or other dialogue is displayed)


    Code
    /usr/bin/find /srv/dev-disk-by-label-S*******E/C******Y/ -mtime +1 -type f -delete

    I also tried removing the -mtime command to see if I could delete all files in the directory:



    Code
    /usr/bin/find /srv/dev-disk-by-label-S*******E/C******Y/ -type f -delete


    This didn't work either.


    Is there anything else I could be overlooking?


    Thanks

    • Offizieller Beitrag

    I can't duplicate your problem. I ran two tests.


    cd /sharedfolders/pxe
    sudo touch test{1,2,3,4,5,6,7,8,9}.txt


    then I add the scheduled job with the command:
    find /sharedfolders/pxe/ -type f -name "*.txt" -delete
    and manually ran it in the web interface. All of the files were deleted.


    Then I copied in a lot of old files to the same directory and manually ran the following command.
    find /sharedfolders/pxe/ -type f -mtime +1 -delete
    All of the files were deleted and none of the directories as expected.


    I have no explanation why your setup isn't working unless the filesystem is read only or it is a remote mount (doesn't look like it).

    omv 7.0.5-1 sandworm | 64 bit | 6.8 proxmox kernel

    plugins :: omvextrasorg 7.0 | kvm 7.0.13 | compose 7.1.4 | k8s 7.1.0-3 | cputemp 7.0.1 | mergerfs 7.0.4


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • Thanks for testing this ryecoaaron. I've now managed to get this working.


    As per your suggestion, this was a permissions issue. While I did have permission set to read/write/executable for root user, I didn't have the "recursive" option selected in the shared folder dialogue. I'm guessing that root didn't have permission to delete files within that folder because of this.


    Running the scheduled job manually has now worked, I'll add the -mtime command back in and see if this works.


    Weirdly, I can't get the "recursive" option to stay on/selected in the shared folders ACL options. I set the option, apply it and then close the dialogue, when I try to edit ACL again the recursive option has deselected itself. I feel this is an issue for another day though.


    Thanks All

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!