Script Installer Help

I'm trying to get my script installer to automatically install a cron job for the server.

I can use this command at the command line:

echo "1 * * * * directory/ >> directory/dumplog.txt 2>&1" >> /var/spool/cron/username

And that will add a cron job for 1 min past to run the said job to said log for said user.

I added this line to the install section of the script installer -

&run_as_domain_user($d, "echo \"1 * * * * $opts->{'dir'}/ >> $opts->{'dir'}/dumplog.txt 2>&1\" >> /var/spool/cron/$username");

And changed the install section start to:

script_merlin_install(&domain, version, &opts, &files, &upgrade-info, username, password) Actually installs merlin, and returns either 1 and an informational message, or 0 and an error

sub script_merlin_install { local ($d, $version, $opts, $files, $upgrade, $username, $password) = @_; local ($out, $ex);

But no cron job seems to be added, am I missing some kind of syntax error, or is there a simpler way to add a cron job (I cant seem to find an API option for it).



If you want to add a cron job, I would use code like the following in the script_merlin_install function, near the bottom :

if (!$upgrade) {
        # Setup the Cron job to run the mailnotify program
        &foreign_require("cron", "");
        local $job = { 'user' => $d->{'user'},
                       'active' => 1,
                       'command' => "$opts->{'dir'}/ >> $opts->{'dir'}/dumplog.txt 2>&1",
                       'mins' => 0,
                       'hours' => 0,
                       'days' => '*',
                       'months' => '*',
                       'weekdays' => '*' };

Just adding to the file in /var/spool/cron won't work, as you also need to restart or signal crond for this to take effect.

Thanks thats great (had to swap the numbers e.t.c. of course but it works). Is there a similar method to add a bootup action?

OK, I've found /usr/libexec/webmin/init/save_action.cgi and I'm going to try and work out how it works using the code in there

OK I have the following now:

&foreign_require("virtualmin-init", ""); local $bootscript = { 'name' => "StartMerlin", 'desc' => "Starts the merlin bot", 'start' => "command/s to start the bot\n",
'stop' => "command/s to stop the bot\n", 'user' => $d->{'user'}, };

This seems to do the job perfectly, though took quite a lot of research to find, is there any proper documentation of the modules or is these sort of requests too rare to justify the time to document it?