LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 11-14-2011, 10:35 AM   #1
tango0202
LQ Newbie
 
Registered: Nov 2011
Distribution: RHEL, CentOS, Debian, Gentoo, Ubuntu
Posts: 19

Rep: Reputation: Disabled
Problem creating script to delete files older than 60 mins


ok so I have created a cron job to delete files older than 60 minutes that is set to run every 4 hours.

0 */4 * * * /home/falon/Enviviocron.sh

What is actually running in the script is "find /home/envivio/*/*.ts -daystart -maxdepth 1 -mmin +60 -type f -name "*.ts" -exec rm -r {}\;

for testing purposes I have changed "rm -r" to "ls -l"

The error that I get when I try to run the command manually is...

Find: paths must precede expression: ls
usage: find [-H] [-L] [-P] [-0level] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

What needs to be changed to allow this to run properly? Got to me something small I am over looking...

Last edited by Tinkster; 11-14-2011 at 12:04 PM. Reason: duh
 
Old 11-14-2011, 12:18 PM   #2
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

Rep: Reputation: 142Reputation: 142
Hi
Not a direct answer to your question, but hoping that this helps, this is the command I use to delete podcasts which are older than 60 days:
Code:
find /mnt/mynas/podcasts/ -mtime +60 -name *.mp4 -exec rm -v '{}' \;
 
Old 11-14-2011, 12:25 PM   #3
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

Rep: Reputation: 142Reputation: 142
You're ending your command with...
Code:
{}\;
...but I end it with...
Code:
'{}' \;
 
Old 11-14-2011, 12:25 PM   #4
tango0202
LQ Newbie
 
Registered: Nov 2011
Distribution: RHEL, CentOS, Debian, Gentoo, Ubuntu
Posts: 19

Original Poster
Rep: Reputation: Disabled
What is the significance of the "-v '{}'" as this is the only real difference in our two scripts?
 
Old 11-14-2011, 12:28 PM   #5
tango0202
LQ Newbie
 
Registered: Nov 2011
Distribution: RHEL, CentOS, Debian, Gentoo, Ubuntu
Posts: 19

Original Poster
Rep: Reputation: Disabled
I have changed the end of the script to how you have yours set and I still get the same error

---------- Post added 11-14-11 at 02:28 PM ----------

is ls -l not an applicable command? does it need to be rm -r or rm -v?
 
Old 11-14-2011, 12:52 PM   #6
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

Rep: Reputation: 142Reputation: 142
Forget the "-v".

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...)?
 
Old 11-14-2011, 01:44 PM   #7
tango0202
LQ Newbie
 
Registered: Nov 2011
Distribution: RHEL, CentOS, Debian, Gentoo, Ubuntu
Posts: 19

Original Poster
Rep: Reputation: Disabled
No special characters in the path directory.

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?
 
Old 11-14-2011, 02:18 PM   #8
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

Rep: Reputation: 142Reputation: 142
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?
 
Old 11-14-2011, 02:54 PM   #9
tango0202
LQ Newbie
 
Registered: Nov 2011
Distribution: RHEL, CentOS, Debian, Gentoo, Ubuntu
Posts: 19

Original Poster
Rep: Reputation: Disabled
Correct the same error is present directly from the shell
 
Old 11-14-2011, 03:11 PM   #10
tango0202
LQ Newbie
 
Registered: Nov 2011
Distribution: RHEL, CentOS, Debian, Gentoo, Ubuntu
Posts: 19

Original Poster
Rep: Reputation: Disabled
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 '{}' \;
 
Old 11-14-2011, 04:27 PM   #11
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
ls is a find directive. Perhaps it's getting confused seeing it after an -exec. What happens if you single-quote the ls?
 
Old 11-15-2011, 07:59 AM   #12
tango0202
LQ Newbie
 
Registered: Nov 2011
Distribution: RHEL, CentOS, Debian, Gentoo, Ubuntu
Posts: 19

Original Poster
Rep: Reputation: Disabled
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.
 
1 members found this post helpful.
Old 11-16-2011, 04:58 PM   #13
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

Rep: Reputation: 142Reputation: 142
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)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] script to delete files older than X days fstab has noatime enabled panseluta Linux - Server 2 07-27-2011 12:18 PM
Script to delete older files not running . linuxlover.chaitanya Linux - Newbie 10 01-12-2009 01:27 AM
Automated script to DELETE files older than 2 days in a Particular folder siddhartha_ece2004 Linux - Newbie 14 07-11-2008 05:46 AM
Script help - delete files older than 45 days but exclude the system files jojothedogboy Linux - Software 3 06-13-2008 03:43 PM
script to auto delete files older than X days nocnoc Programming 17 12-06-2006 08:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration