I know it's not polite to ask for support on a script which is not supported but I would really appreciate it if any of you gurus can help me sort out the problem. Here is a script written by Eli ... yeah bluehat.
This is a cron script for which you throw a bunch of crontab lines and it makes sure that they won't overlap and put strain on the server. Here's the code.
#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI qw/:cgi-lib/;
use CGI::Carp qw(fatalsToBrowser);
%FORM=Vars();
#Instructions
##################
#Set this to the server path to the crons.txt
$pathtocrontxt="/home/username/public_html/cgi-bin/crons.txt";
# In the crons.txt put the first line as 0 and then put each cronjob on a seperate line below
# set the chmod permissions to crons.txt to 777 and cron.cgi to 755
#####################################
print "Running Crons...\n";
open(INF,"$pathtocrontxt") or print "couldnt open file";
@commands=<INF>;
close(INF);
foreach $line(@commands){
chomp($line);
if($line == 0){
print "not working\n";
@commands[0]="1\n";
open(OUTF,">$pathtocrontxt");
foreach $command(@commands){
print OUTF "$command";
}
close(OUTF);
}
elsif($line == 1){
print "working";
exit;
}
else {
print "Executing: $line\n";
$output=system("$line");
print "$output\n";
}
}
@commands[0]="0\n";
open(OUTF,">$pathtocrontxt");
foreach $command(@commands){
print OUTF "$command";
}
close(OUTF);
print "\n\nDone!\n";
Here's the contents of crontab.txt
0
ping www.google.com
ping www.google.com.hk
ping www.google.com.au
ping www.google.com.sg
ping www.google.com.my
and here's the error I got from crontab email.
Content-type: text/html
Running Crons...
not working
not working
Done!
From my limited knowledge, I can tell that it checks for 0 on the crons.txt first line and if true print "Not working" and change it to 1 and prints out the commands and executes it. May I know why it's not working? TIA
