You are not logged in.

#1 2008-11-03 11:22:51

Barrucadu
Member
From: York, England
Registered: 2008-03-30
Posts: 1,158
Website

uCron - Userspace Cron

http://blog.barrucadu.co.uk/2008/11/ucr … pace-cron/

I found myself in need of running a script every hour, and get the result reported to me with notify-send. I found no easy way to do this with regular cron, as notify-send needs to be run from within an X session (or so my limited knowledge says), so I decided to write a simple python script to run commands every minute, half hour, and hour.

#!/usr/bin/env python

import time, datetime, os

while(True):
    now = datetime.datetime.now()

    # Run minutely commands.
    os.system("for script in ~/cron/minute/*; do $script; done")

    if now.minute == 30:
        # Run bihourly commands.
        os.system("for script in ~/cron/halfhour/*; do $script; done")
    elif now.minute == 0:
        # Run bihourly and hourly commands.
        os.system("for script in ~/cron/halfhour/*; do $script; done")
        os.system("for script in ~/cron/hour/*; do $script; done")

    time.sleep(60)

Just make the directories ~/cron/minute, ~/cron/halfhour, and ~/cron/hour, stick a call to uCron in your gnome-session (or whatever you use), and away you go!

Offline

Board footer

Powered by FluxBB