[SOLVED] Problem creating script to delete files older than 60 mins
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Mmmhh, that's weird - I created a file called "with space" together with other files and the command works:
Code:
#find /home/*/*with* -daystart -maxdepth 1 -mmin +5 -type f -name "*with*" -exec ls '{}' \;
/home/scripts/with space
You don't have by chance some directories with weird names (blanks, special chars) in your path (/home/envivio/) that might perhaps create some problems (no clue...)?
I changed the script to "find /home/envivio/*/*.ts -daystart -maxdepth 1 -mmin +60 -type f -name "*.ts" -exec ls '{}' \; and I still receiver the "paths must precede expression: ls" error. I am hesitant to replace "ls" with "rm" until I can see this script list all the files in this path directory correctly. Do I need to add #!/bin/bash to the line before the "find" script?
If it doesn't work with "ls", it won't work with "rm".
But just to be clear, if you run the command directly from the shell you get the same error message, right?
just to add to that last comment....I tried just running the "find" command and it works like it is supposed to but it is slightly different than what I have in the shell script. Also another thing to note is this OS is ubuntu...will I need to add "sudo" in front of this line in the shell? Or will this not matter because the cron job was created under the root user?
Whats works....
find /home/envivio/*/*.ts -daystart -maxdepth 1 -mmin +59 -type f -name "*.ts" -exec ls -l {} \;
What does not work...this does not work in the shell or the command line directly.
find /home/envivio/*/*.ts -daystart -maxdepth 1 -mmin +60 -type f -name "*.ts" -exec ls -l '{}' \;
I finally got it to work, I used the top command in the last post with '{}' \; instead of {}\; and then I used +59 instead of +60...which make sense now. within the -mmin field there cannot get a value greater than +59 because anything with a value greater than +60 you would need to use -mtime.
Maaaan, I can't believe it - 59 works, but 60 doesn't.
Why does it care? It should digest any integer that is valid for the OS as integer - it's a minutes parameter, so it shoudn't matter if the value is more or less than an hour.
Compliments for your findings!!!
(and don't forget, pls. mark the thread as solved)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.