Cron file maintenance via web page (or other) ...

3rd Party Package Requesting

Cron file maintenance via web page (or other) ...

Postby bob selby » Fri Aug 27, 2010 10:03 am

Is there a crontab file editor that can be put on the 040 web page ??

What I need is an easy way to add/delete cron entries from a remote windows machine and have crond restart when the file is updated.

I have written a windows app to maintain the file but have yet to figure out a way to have crond restart automagically. It does the job but a web interface would be nicer.

Also, can the crond be made to recognize that the file has updated - and restart?? Perhaps a cron job that forks a script ??

TIA
Bob
bob selby
Advanced Member
 
Posts: 295
Joined: Wed Nov 21, 2001 8:18 am
Location: London, UK

Re: Cron file maintenance via web page (or other) ...

Postby Lightning » Fri Aug 27, 2010 7:49 pm

The simplest way to do what you are asking would be to just add a small script into the system for monitoring the cron configuration file and then restart it when it is changed. Off of the top of my head something like this
:> /boot/bin/cronmon
chmod +x /boot/bin/cronmon
edit /boot/bin/cronmon
Code: Select all
#!/bin/sh

. /etc/.language
. /etc/$DLANG.cch

set -- `ls -l /etc/cron/root`
OLD=$5$8

while :
do        set -- `ls -l /etc/cron/root`
            CURRENT=$5$8
            if [ $CURRENT != $OLD ]
            then    rc_crond $rest
                       OLD=$CURRENT
             fi
             sleep 30
done

edit /rc/rc_user
Code: Select all
$star)
       runchk cronmon
       [ $? = 1 ] && fork cronmon
       ;;
        $stop)
       runchk cronmon
       [ $? = 1 ] || killall cronmon
       ;;


Once completed you should be able to just use "rc_user start" for the very first time and then it will be automatic from then on and any time you edit the cron configuration it will restart within 30 seconds.

If you don't like that way of doing it there is actually a new BETA "webmin-1.510-lightning" package in the package listing if you have updated it within the last week or two. But I don't remember if the "minimal" version includes cron editing or not, but I am thinking that it does. I have not really done any testing of it other than main function.
If you are afraid that you might make a mistake. The chances are high that you will never learn anything.
User avatar
Lightning
FREESCO GOD !!
 
Posts: 3049
Joined: Wed Nov 14, 2001 6:50 am
Location: Oregon, USA

Re: Cron file maintenance via web page (or other) ...

Postby bob selby » Sat Aug 28, 2010 4:28 am

I'll have a play with your scripts later today ...

I installed your beta webmin package and it does have CRON maintenance :-)

However, it is very confusing as there are at least twice as many enries as there are in my actual cronfile.

Also on the home sceen of webmin there is a nag "Warning - Your system is actually running Generic Linux version 2.0."

I was carefull NOT to press the associated button without checking :-)

Best regards,
Bob
bob selby
Advanced Member
 
Posts: 295
Joined: Wed Nov 21, 2001 8:18 am
Location: London, UK

Re: Cron file maintenance via web page (or other) ...

Postby Lightning » Sat Aug 28, 2010 1:34 pm

I did do a VERY small amount of changing in the webmin configuration and it MIGHT work correctly for changing the crond entries. But I did NOT test it in any way for functionality in actually making crond changes. as for the generic Linux 2.0, that is correct.

If anyone takes the time to change all of the various configuration in the generic-Linux for webmin and gives me the updates then the package could be removed from beta status.
If you are afraid that you might make a mistake. The chances are high that you will never learn anything.
User avatar
Lightning
FREESCO GOD !!
 
Posts: 3049
Joined: Wed Nov 14, 2001 6:50 am
Location: Oregon, USA

Re: Cron file maintenance via web page (or other) ...

Postby bob selby » Sat Aug 28, 2010 2:30 pm

OK, thanks for that :-)
Bob
bob selby
Advanced Member
 
Posts: 295
Joined: Wed Nov 21, 2001 8:18 am
Location: London, UK

Re: Cron file maintenance via web page (or other) ...

Postby bob selby » Mon Aug 30, 2010 4:30 am

I tried your cronmonitor script - and it "did what it says on the tin" :-)

However, whenever I restarted the machine although the crond appeared in the "ps" list the /var/.cron_running file wasnt being touched (nor was my other 1 min script being run).

Having "fiddled about a bit" it seems that crond hates anyone processing the cron file while it is running ... so now I copy /etc/cron/root to root.crontab at startup and edit that and have cronmon test that, halt crond, move copy.crontab to root and restart crond.

Code: Select all
#!/bin/sh

. /etc/.language
. /etc/$DLANG.cch

# It seems that CROND really *HATES* anyone touching the cron file
# while its running

if [ ! -f /etc/cron/root.crontab ]
then    rc_crond stop
        cp /etc/cron/root /etc/cron/root.crontab
        sync
        rc_crond start
fi

set -- `ls -l /etc/cron/root.crontab`
OLD=$5$8

while :
do  set -- `ls -l /etc/cron/root.crontab`
    CURRENT=$5$8
    if [ $CURRENT != $OLD ]
    then    rc_crond stop
            rm /etc/cron/root
            cp /etc/cron/root.crontab /etc/cron/root
            cp /etc/cron/root /boot/etc/cron.cfg
            sync
            OLD=$CURRENT
            echo "Updated OK" >/var/cronmon.log
            rc_crond start
     fi
     sleep 30
done


This seems much better, but I still find crond gets stuck as before on a system reboot, though doing a rc_crond restart seems to poke it back into life.

Any ideas as to how I can make it 100% reliable??
Bob
bob selby
Advanced Member
 
Posts: 295
Joined: Wed Nov 21, 2001 8:18 am
Location: London, UK

Re: Cron file maintenance via web page (or other) ...

Postby Lightning » Mon Aug 30, 2010 6:06 pm

The real problem here is probably not editing the root file for crond. But rather the ownership or even read right issue when edited by anyone who is not root. So most likely this is an ownership issue.
Code: Select all
#!/bin/sh

    . /etc/.language
    . /etc/$DLANG.cch

    # It seems that CROND really *HATES* anyone touching the cron file
    # while its running

    if [ ! -f /etc/cron/root.crontab ]
    then rc_crond $stop
            cp /etc/cron/root /etc/cron/root.crontab
            chown root:root /etc/cron/root
            chmod 0600 /etc/cron/root
           sync
           rc_crond $star
    fi

    set -- `ls -l /etc/cron/root.crontab`
    OLD=$5$8

    while :
    do  set -- `ls -l /etc/cron/root.crontab`
        CURRENT=$5$8
 
      if [ $CURRENT != $OLD ]
        then rc_crond $stop
                rm /etc/cron/root
                cp /etc/cron/root.crontab /etc/cron/root
                chown root:root /etc/cron/root
                chmod 0600 /etc/cron/root
                cp /etc/cron/root /boot/etc/cron.cfg
                sync
                OLD=$CURRENT
                echo "Updated OK" >/var/cronmon.log
                rc_crond $star
         fi
         sleep 30
    done
If you are afraid that you might make a mistake. The chances are high that you will never learn anything.
User avatar
Lightning
FREESCO GOD !!
 
Posts: 3049
Joined: Wed Nov 14, 2001 6:50 am
Location: Oregon, USA

Re: Cron file maintenance via web page (or other) ...

Postby bob selby » Tue Aug 31, 2010 3:09 am

Works a treat :-)

Once again you have provided excellent support :-)

Thanks,
Bob
bob selby
Advanced Member
 
Posts: 295
Joined: Wed Nov 21, 2001 8:18 am
Location: London, UK

Re: Cron file maintenance via web page (or other) ...

Postby Lightning » Tue Aug 31, 2010 4:52 am

One thing that I did not really pay attention to was
echo "Updated OK" >/var/cronmon.log
Instead of that line you might consider using this line
Code: Select all
logger -p info -t cronmon "Updated OK"

This will put the messages into the standard info logs and it is monitored by the system for file size so the ramdisk won't fill up eventually.
If you are afraid that you might make a mistake. The chances are high that you will never learn anything.
User avatar
Lightning
FREESCO GOD !!
 
Posts: 3049
Joined: Wed Nov 14, 2001 6:50 am
Location: Oregon, USA

Re: Cron file maintenance via web page (or other) ...

Postby bob selby » Tue Aug 31, 2010 5:20 am

Thanks - I wondered the best way to do that :-)

Which is why I did ">" and not ">>" :-)

Thanks,
Bob
bob selby
Advanced Member
 
Posts: 295
Joined: Wed Nov 21, 2001 8:18 am
Location: London, UK

Re: Cron file maintenance via web page (or other) ...

Postby Lightning » Tue Aug 31, 2010 7:39 pm

Which is why I did ">" and not ">>"
Hehe, I missed that little detail. :roll:
If you are afraid that you might make a mistake. The chances are high that you will never learn anything.
User avatar
Lightning
FREESCO GOD !!
 
Posts: 3049
Joined: Wed Nov 14, 2001 6:50 am
Location: Oregon, USA


Return to 3rd Party Package Requesting

Who is online

Users browsing this forum: No registered users and 0 guests

cron