[GLLUG] crontabs

Michael Watters wattersm at liquidweb.com
Tue Jun 10 20:35:29 EDT 2003


Todd Torrey wrote:

> I was wondering if directly editing a crontab without using "crontab" is
> strictly prohibited.
> I want to be able to edit a crontab via a script without any user
> interaction. Is this o.k.?
> To be more specific about my intentions, I want to serve a web page showing
> the contents of a crontab and also allow editing the crontab via a web form.
>
> Thanks,
> Todd
>
> _________________________________________________________________
> Add photos to your messages with MSN 8. Get 2 months FREE*.
> http://join.msn.com/?page=features/featuredemail
>
> _______________________________________________
> linux-user mailing list
> linux-user at egr.msu.edu
> http://www.egr.msu.edu/mailman/listinfo/linux-user

I did something similar with the Acoount Services Manager for accounts on my
server.  I wrote a simple python CGI script that acts as a crontab editor.  The
web page is created by a perl script which calls the editor script.

#!/usr/bin/python

###
### Account Services Manager - Crontab Module - Crontab Editor
###

import sys
import time

time.sleep(1)

f = file(sys.argv[1], 'w')

for line in sys.stdin.readlines():
    f.write(line)

f.close()

This will take the standard input and install it as the new crontab.  You will
need edit your CGI script to pass the appropriate input.

Here are the lines from my main CGI that calls the python editor script.

sub InstallCrontab
{
    if(@tasks) {
        pipe(IN, OUT);
        my $pid = fork();
        if($pid) {
            foreach(@tasks) {
                print OUT "$_\n";
            }
        }
        else {
            open(STDIN, "<&IN");
            $ENV{'VISUAL'} = "$MODULE::Path/editor.py";
            exec($crontab_exe, '-u', $AUTH::User, '-e');
            exit(1);
        Show_Back_Link();
        }
    }
    else {
        print "<font face=\"verdana, arial\" size=\"2\">Your new crontab is
empty. Removing crontab...</font><br>\n";
        RemoveCrontab();
    }
}

You can see the entire crontab module by download the ASM program from
www.acctmgr.com.  I couldn't get the crontab editor that is included with the
program to work, so I wrote my own.

Hope this helps you out a little bit.



More information about the linux-user mailing list