Cron job to run once a day is not working.

bhupendra2895

New Member
Messages
554
Reaction score
20
Points
0
I created a cron job to delete all files in a temperory directory once a day at 13:00. But it is not working. Since I don't have any experience with cron jobs, there can be mistake. Please tell me what mistake I have done.
This is the format :-
(MINUTE HOUR DAY MONTH WEEKDAY COMMAND ACTIONS)
(00 13 * * * rm-R/home/bhupendr/public_html/temp/*)
I am on starka with free hosting plan. If it has anything to do with it.
 

zapzack

New Member
Messages
606
Reaction score
19
Points
0
I created a cron job to delete all files in a temperory directory once a day at 13:00. But it is not working. Since I don't have any experience with cron jobs, there can be mistake. Please tell me what mistake I have done.
This is the format :-
(MINUTE HOUR DAY MONTH WEEKDAY COMMAND ACTIONS)
(00 13 * * * rm-R/home/bhupendr/public_html/temp/*)
I am on starka with free hosting plan. If it has anything to do with it.

change the command to
Code:
find /home/bhupendr/public_html/temp -exec rm -f {} \;
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
How, exactly, is it not working? Is nothing deleted? Are some things not deleted? Are you getting any e-mailed output from the command?

Also try the command: rm -Rf /home/bhupendr/public_html/temp/*. The -f is to force deletion without asking for user input. Note also the space between the options and the path.
 
Last edited:

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
I was under the impression that you could only call PHP, Perl and a couple others. This would be a pretty easy thing to implement in PHP and would also allow for multiple things to run under one command too
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
I was under the impression that you could only call PHP, Perl and a couple others.
That could very well be. However, I believe that rm is installed as a binary rather than a built-in shell command (it certainly isn't a bash built-in), and should thus be accessible (though the full path to the binary might need to be given). find is definitely a binary. I can't check right now, but I believe both binaries have global execute permission.

Cron doesn't have any blacklisting or whitelisting capabilities that I'm aware of, so it can't filter out certain binaries.

This would be a pretty easy thing to implement in PHP and would also allow for multiple things to run under one command too
Seconded. A script would be much more flexible.
 
Last edited:

bhupendra2895

New Member
Messages
554
Reaction score
20
Points
0
@Mission Files didn't get deleted with old cron job.
@Zapzack I will try the command suggested with -f option , and see if it works.Otherwise I have to do it with Php.I will post the result here.
 

bhupendra2895

New Member
Messages
554
Reaction score
20
Points
0
All commands posted above seems to be not working.I thought this can be problem with server time.So I ran date(r) and used 10 minutes ahead of that time to set cron job.But files are there.
How can execute Php script using cron and also where I can get tutorial for webmasters about using cron job.Thanks
 
Last edited:

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
To execute a PHP cron job, enter this:
/usr/bin/php /home/YOUR_USERNAME/public_html/PATH_TO_FILE
In the PHP script you should then use readdir() to get the list of files in the selected directory and then use unlink() to delete each of those files.
 
Top