View previous topic :: View next topic |
Author |
Message |
summitmn Smarty Rookie
Joined: 13 Sep 2005 Posts: 5
|
Posted: Tue Sep 13, 2005 8:08 pm Post subject: cron job to empty templates_c |
|
|
Does anyone have a cron job that will empty the templates_c folder on a regular basis? |
|
Back to top |
|
Duncan Smarty Pro
Joined: 16 Dec 2003 Posts: 166
|
Posted: Tue Sep 13, 2005 8:22 pm Post subject: |
|
|
I've never had any problems with the templates_c content, but usually provide a "clear content" functionality in the admin section, based on the http://smarty.php.net/manual/en/api.clear.compiled.tpl.php function.
You could create a small script for a cron job with it. |
|
Back to top |
|
summitmn Smarty Rookie
Joined: 13 Sep 2005 Posts: 5
|
Posted: Tue Sep 13, 2005 9:03 pm Post subject: cron job |
|
|
Sorry, I'm not much of a coder, could you provide some help as to what the script would look like to run in order to clear out the template_c directory? I would like to run it on the command line as a cron job(automatically run every month or something like that)...do I need a php script or use some other language? What would the script look like? |
|
Back to top |
|
summitmn Smarty Rookie
Joined: 13 Sep 2005 Posts: 5
|
Posted: Thu Sep 15, 2005 3:46 pm Post subject: first attempt |
|
|
Here is a php script that I tried to run to clear out the templates_c directory. However when I tried to run the script I got the following error:
rm: cannot lstat `*': No such file or directory
My code is below. Any ideas on how to fix it so that the rm command works?
Code: |
<?php
$dirpath="/home/username/smarty/templates_c";
$command="rm -r *";
if ($handle = opendir($dirpath)) {
system($command);
}
?> |
|
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Thu Sep 15, 2005 4:00 pm Post subject: |
|
|
Why dont using a simple bash script for that? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Sep 15, 2005 6:44 pm Post subject: |
|
|
You want to clear out compiled files that have not been accessed in quite some time, yes? This will remove all files not accessed in the last five days. You can run it daily or whatever.
Code: | #!/bin/sh
/usr/bin/find /path/to/templates_c/. -atime +5 -exec rm -rf {} \; |
Be certain to put the /. on the end of the path so the template_c directory itself doesn't get removed.
I tend to avoid scripts that use wildcards ie. "rm -rf *", those typically run into the limitations of shell arguments when you have lots of files to remove.
Last edited by mohrt on Fri Sep 16, 2005 4:20 pm; edited 1 time in total |
|
Back to top |
|
summitmn Smarty Rookie
Joined: 13 Sep 2005 Posts: 5
|
Posted: Fri Sep 16, 2005 3:23 pm Post subject: thanks |
|
|
mohrt,
thanks, i did that...that was really helpful! |
|
Back to top |
|
summitmn Smarty Rookie
Joined: 13 Sep 2005 Posts: 5
|
Posted: Mon Sep 19, 2005 4:07 pm Post subject: removing subdirs |
|
|
mohrt,
templates_c also contains a lot of directories. How would I edit the command to delete not just the files older than 5 days, but also the subdirectories older than 5 days? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Sep 19, 2005 4:54 pm Post subject: |
|
|
The find command works recursively, so it should work as expected. |
|
Back to top |
|
|