Hi,
First off, thanks in advance to anyone who can offer some advice on the following script...
Basically, in the script below, I am printing text output to a file that I intend to use as a crontab.
As you can see, starting from the first "foreach" loop, I am running a set of Perl commands for each $listitem . Then, to finish off the loop, I print out CRON job text.
This is where I get lost: I want to assign each $listitem to its own CRON job that executes in increments of 5 minutes throughout the day, that is, starting from 0 0 * * *, one of my cron jobs should start. When the time reaches 55 0 * * *, the next CRON job should roll the hour over to 1, and begin in five minute intervals once again, ie: 0 1 * * *, 5 1 * * *, 10 1 * * *...
The problem I am having is this... When I run the script, instead of assigning one instance of $listitem to each time increment, the script assigns EVERY 5 increment to an instance of $listitem, THEN moves to the next $listitem and assigns every increment again... I've posted the script below and the output...
OUTPUT:
5 * * * /usr/bin/php /var/10 * * * /usr/bin/php /var/15 * * * /usr/bin/php /var/20 * * * /usr/bin/php /var/25 * * * /usr/bin/php /var/30 * * * /usr/bin/php /var/35 * * * /usr/bin/php /var/40 * * * /usr/bin/php /var/45 * * * /usr/bin/php /var/50 * * * /usr/bin/php /var/55 * * * /usr/bin/php /var/
## SHOULD HAVE ROLLED OVER TO HOUR 1 !!
0 * * * /usr/bin/php /var/5 * * * /usr/bin/php /var/10 * * * /usr/bin/php /var/15 * * * /usr/bin/php /var/20 * * * /usr/bin/php /var/25 * * * /usr/bin/php /var/30 * * * /usr/bin/php /var/35 * * * /usr/bin/php /var/40 * * * /usr/bin/php /var/45 * * * /usr/bin/php /var/50 * * * /usr/bin/php /var/55 * * * /usr/bin/php /var/
Thanks for the help!
First off, thanks in advance to anyone who can offer some advice on the following script...
Basically, in the script below, I am printing text output to a file that I intend to use as a crontab.
As you can see, starting from the first "foreach" loop, I am running a set of Perl commands for each $listitem . Then, to finish off the loop, I print out CRON job text.
This is where I get lost: I want to assign each $listitem to its own CRON job that executes in increments of 5 minutes throughout the day, that is, starting from 0 0 * * *, one of my cron jobs should start. When the time reaches 55 0 * * *, the next CRON job should roll the hour over to 1, and begin in five minute intervals once again, ie: 0 1 * * *, 5 1 * * *, 10 1 * * *...
The problem I am having is this... When I run the script, instead of assigning one instance of $listitem to each time increment, the script assigns EVERY 5 increment to an instance of $listitem, THEN moves to the next $listitem and assigns every increment again... I've posted the script below and the output...
Code:
#!/usr/bin/perl
use File::Copy::Recursive qw(dircopy);
use File::Copy;
$userdir = "/var/[URL unfurl="true"]www/web12/web/";[/URL]
$sourcefiles = "/home/source";
$sourcedir = "play";
$ftd1 = "bm";
opendir $sourcedir, ".";
@contents = grep /$ftd1/, readdir $sourcedir;
closedir $sourcedir;
foreach $listitem ( @contents )
{
chdir $userdir;
mkdir ($listitem, 0777);
dircopy($sourcefiles,$userdir.$listitem."/");
copy("/home/play/".$listitem, $userdir.$listitem."/myfolder/ak.txt");
open(OUT_FILE,">>web12.txt");
for ($count=0; $count<12; $count++)
{
$a = ($count * 5);
print OUT_FILE $a."\0 * * * /usr/bin/php /var/[URL unfurl="true"]www/web12/web/".$listitem."/myfolder/rollcall.php[/URL] \n";
}
}
OUTPUT:
5 * * * /usr/bin/php /var/10 * * * /usr/bin/php /var/15 * * * /usr/bin/php /var/20 * * * /usr/bin/php /var/25 * * * /usr/bin/php /var/30 * * * /usr/bin/php /var/35 * * * /usr/bin/php /var/40 * * * /usr/bin/php /var/45 * * * /usr/bin/php /var/50 * * * /usr/bin/php /var/55 * * * /usr/bin/php /var/
## SHOULD HAVE ROLLED OVER TO HOUR 1 !!
0 * * * /usr/bin/php /var/5 * * * /usr/bin/php /var/10 * * * /usr/bin/php /var/15 * * * /usr/bin/php /var/20 * * * /usr/bin/php /var/25 * * * /usr/bin/php /var/30 * * * /usr/bin/php /var/35 * * * /usr/bin/php /var/40 * * * /usr/bin/php /var/45 * * * /usr/bin/php /var/50 * * * /usr/bin/php /var/55 * * * /usr/bin/php /var/
Thanks for the help!
