Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

cron job to empty templates_c

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
summitmn
Smarty Rookie


Joined: 13 Sep 2005
Posts: 5

PostPosted: Tue Sep 13, 2005 8:08 pm    Post subject: cron job to empty templates_c Reply with quote

Does anyone have a cron job that will empty the templates_c folder on a regular basis?
Back to top
View user's profile Send private message
Duncan
Smarty Pro


Joined: 16 Dec 2003
Posts: 166

PostPosted: Tue Sep 13, 2005 8:22 pm    Post subject: Reply with quote

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
View user's profile Send private message
summitmn
Smarty Rookie


Joined: 13 Sep 2005
Posts: 5

PostPosted: Tue Sep 13, 2005 9:03 pm    Post subject: cron job Reply with quote

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
View user's profile Send private message
summitmn
Smarty Rookie


Joined: 13 Sep 2005
Posts: 5

PostPosted: Thu Sep 15, 2005 3:46 pm    Post subject: first attempt Reply with quote

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
View user's profile Send private message
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Thu Sep 15, 2005 4:00 pm    Post subject: Reply with quote

Why dont using a simple bash script for that?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Sep 15, 2005 6:44 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
summitmn
Smarty Rookie


Joined: 13 Sep 2005
Posts: 5

PostPosted: Fri Sep 16, 2005 3:23 pm    Post subject: thanks Reply with quote

mohrt,
thanks, i did that...that was really helpful!
Back to top
View user's profile Send private message
summitmn
Smarty Rookie


Joined: 13 Sep 2005
Posts: 5

PostPosted: Mon Sep 19, 2005 4:07 pm    Post subject: removing subdirs Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Sep 19, 2005 4:54 pm    Post subject: Reply with quote

The find command works recursively, so it should work as expected.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP