Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timer

Status
Not open for further replies.

fergmj

Programmer
Feb 21, 2001
276
US
I have a cgi script and it looks into a directory to see if there are any new files and if there are, it creates links to the files in the form of a new index.html page.

However, how do I get it to look into the directory say every 30 seconds to see if there are new files?

Many thanks.

Mindy
 
If you're on a unix system, use cron. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
How would I use this on a script that isn't going to be called from a webpage? This is a script that will reside on a unix bax in the cgi-bin directory for a website but I want it to run automatically.

Thanks for the help.

Mindy
 
cron? for every 10 seconds??? cron (or a scheduled task on a Win OS) would work, but,...

I would rather run the CGI for some number of iterations on some period. This does have the annoying effect of taking the user back to the top of the page on each refresh.


Code:
#!/usr/local/bin/perl
use CGI;
$q = new CGI;
$this = $q->url();
$step = $q->param(step) + 1;
$url = $this."?step=$step";
opendir(DIR,"./");
@files = grep !/^\.\.$/, readdir DIR;
closedir DIR;

if ($step < 9 ) { print $q->header(-Refresh=>&quot;10; URL=$url&quot;);}
else { print $q->header; }

print $q->start_html,
	$q->p(&quot;stepped to $step&quot;);
foreach (@files) { print qq(<p><a href=&quot;$_&quot;>$_</a></p>\n); }
print $q->end_html;
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
2 goBoating:
What &quot;but,...&quot;

2 goBoating:
For every request do recursive check of directories, then create index file and only after it send request back.
And if you'll have 4 requests every second? Or i misunderstand your idea, if so, i apologize.

2 fergmj:
Cron can execute progs every minute. Standard cron could not do it every second. But it easy could be solved.

in the unix shell:
crontab -e

then
*/1 * * * * /usr/local/apache/vhosts/mysite/cgi-bin/mysqipt.pl

This will execute your script every minute.
But in script you can do two iterations with 30 seconds periods.
 
cron? for every [red]10[/red] seconds???
ooops! the original post says '30 seconds' :~/

lightElf,
I guess the more efficient approach would depend on how many times the URI gets hit. The question is &quot;how do you want to trigger the survey of the directory/file structure&quot;.

If it sees only a few (maybe up to several humdred) hits per day, then getting the CGI to do the refresh work is cheaper than firing a cron job every minute. There would probably be a major chunk of overnight time when there would be zero or nearly zero requests. Fold mod_perl into the equation and this gets reasonably fast and efficient.
Obviously, peak load situations would be important to watch.

Conversely, if the URI will get lots of hits, then the cron approach could be cheaper.

Also, if I went with the CGI approach, I would not write the index file to disk.....Just send the info back to the browser.

From the sys admin perspective, I tend to discourage most users from using crontabs. They tend to use them inappropriately and you end up with lots of cron 'noise', so to speak... things that would be done better another way or on a different cron schedule, or forgotten and running for weeks/months/years. I know a few sys admins that won't even let their general user population do crons.

I guess, as is usually the case, TMTOWTDI ;-) Hopefully, Mindy will find something that works well for her.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
goBoating: You are right. Àbsolutely.

and i hope &quot;Mindy will find something that works well for her&quot;.

and i apologize for my english, it has conditionned my so emotional utterance.
 
goBoating: all very good points. I was just being lazy and mentioned the easiest way to do it. I had forgotten that cron wouldn't let you do seconds, just minutes. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top