LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-29-2015, 11:12 PM   #1
ASTRAPI
Member
 
Registered: Feb 2007
Posts: 210

Rep: Reputation: 16
Question Command manual working but not on cron


Hi

When i run this command manually on Centos 6.6 it works:

Code:
/usr/bin/find /backup/ -type d -mtime +1 -print0 | xargs -0 rm -rf
but as a cron job it doesn't as i can see a folder with files there from Mar 28:

Code:
55 5 * * * /usr/bin/find /backup/ -type d -mtime +1 -print0 | xargs -0 rm -rf
And here are the logs from cron that it is executing this at the correct time :

Code:
Mar 30 05:55:01 server CROND[9526]: (root) CMD (/usr/bin/find /backup/ -type d -mtime +1 -print0 | xargs -0 rm -rf)
Any ideas why?

Thanks

Last edited by ASTRAPI; 03-29-2015 at 11:42 PM.
 
Old 03-29-2015, 11:22 PM   #2
Tchiarot
Member
 
Registered: Feb 2013
Location: Lima, Peru
Distribution: Debian
Posts: 39

Rep: Reputation: Disabled
Could be an enviroment variable, try to put in a bash and export PATH.
 
Old 03-29-2015, 11:27 PM   #3
ASTRAPI
Member
 
Registered: Feb 2007
Posts: 210

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by Tchiarot View Post
Could be an enviroment variable, try to put in a bash and export PATH.
How?
 
Old 03-30-2015, 01:02 AM   #4
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Code:
#!/bin/bash
/usr/bin/find /backup/ -type d -mtime +1 -print0 | /usr/bin/xargs -0 /bin/rm -rf
Code:
chmod +x scriptfilename
Run this script with cron.
 
1 members found this post helpful.
Old 03-30-2015, 02:11 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
Perhaps also try the full path for all commands as per veerain's example within cron
 
Old 03-30-2015, 02:55 AM   #6
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Did you try to remove the "old" directory by hand? Might be some extra on that one that keeps it from beeing deleted? Check lsattr.
To me everything seems good with the cron. At least its run. Should check the output of the actuall run. Dunno if centos sends mail to the owner of the cron job if it generates output. Might check that out and enable it. Elsewise just redirect everything to a file.
 
Old 03-30-2015, 07:50 AM   #7
ASTRAPI
Member
 
Registered: Feb 2007
Posts: 210

Original Poster
Rep: Reputation: 16
I did it but is not working

log:

Code:
Mar 30 14:45:01 server CROND[5828]: (root) CMD (/scriptb/cleanbackups.sh)
My cron:

Code:
45 14 * * * /scriptb/cleanbackups.sh
And my file cleanbackups.sh :
Code:
#!/bin/bash
/usr/bin/find /backup/ -type d -mtime +1 -print0 | /usr/bin/xargs -0 /bin/rm -rf
And yes i chmod +x the file...
 
Old 03-31-2015, 12:40 AM   #8
ASTRAPI
Member
 
Registered: Feb 2007
Posts: 210

Original Poster
Rep: Reputation: 16
Ok it works now thanks

Last edited by ASTRAPI; 03-31-2015 at 12:55 AM.
 
Old 03-31-2015, 04:26 AM   #9
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
So what you did to make it work.
 
  


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
Cron runs only manual on Centos ASTRAPI Linux - Newbie 5 11-25-2014 05:03 PM
[SOLVED] Not sure why this command isn't working under bash and cron cheddarcheese Linux - Newbie 4 05-12-2013 11:04 AM
Unexpected results: Difference in Perl Script Behavior between manual and cron runs EnderX Programming 3 12-11-2010 12:42 AM
Command not working in cron job, but works fine in root Roosta21 Linux - Software 4 11-22-2007 09:08 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 02:57 AM


All times are GMT -5. The time now is 10:36 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration