Martin,
There is a way to do this, but you might face the risk of your server administrator shutting down this program, and you might find it hard to shut down this program once you started it. For the purpose of this example, I will use the term "mini-cron" to relate to the program that will emulate the cron job, it is not actually related to cron in any way.
You will need basically four programs to do this, two will allow you to start and stop the "mini-cron", one will be the "mini-cron" itself, and the third will be the program you want "mini-cron" to run.
In the first program, we will call it cronstart:
Code:
#!/usr/bin/perl
my $job = "/path/to/mini-cron";
print "Content-type:text/html\n\n";
print "<h1>Starting your job</h1>";
print `$job`;
Note on print `$job`; we use left quote, which are typically under the ~ symbol on a PC keyboard.
As for the kill procedure, this will vary ALOT depending on your OS. I won't go into the kill procedure at this time, so if you think you will need this, let me know and I will post it. Next, "mini-cron":
Code:
#!/usr/bin/perl
# Welcome to mini-cron
my $job = "/path/to/program_for_cron";
my $delay = 600; # sleep delay in seconds 600 = 10 minutes
my $log = 0; # Turn logging of output on (1) or off (0)
my $log_file = "log.txt";
while (1) {
my $error = `$job`; # Error is actually whatever is outputted by the program
&log_errors($error) if ($log_on); # IF you want to
sleep $delay;
}
sub log_errors {
my $error = @_;
open (FILE, ">> $log_file);
print FILE "$error";
close FILE;
}
You could also change this code so that instead of while (1) you used a conditional statement to run a specific number of times, or however you wanted to do this. As you can see, this program runs an infinite loop. This can be very dangerous, and most likely, the server admin will shut it down if it sees this process running continually. As a suggestion, you might try something a bit different:
Code:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
print `man crontab;crontab -l`;
What this will do is see if crontab is installed on your system, and show you how to use it. If it is installed, I would strongly suggest manipulating the shell though a perl or csh cgi rather than using the methods described above. Its much less overhead for everyone involved. I can post methods to handle this if you wish.
Hope this helps,
------------------
Fred Hirsch
Web Consultant & Programmer