More silly projects - Crontab safe to play with?

Discussion in 'OT Technology' started by Astro, Mar 10, 2003.

  1. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    Basically, is crontab safe to play with from a scripting standpoint (say from Perl for example)? I know its a text file, but it appears it requires an "install" once saved and I'm wondering if just writing to it would be enough to get he job done.

    I'm tempted to monkey with it, but at the same time, I don't want to break it (at least not on this box). Here's the silly project part of this:

    - This Linux box runs a handful of crontab jobs, but two of them are actually sustaining life :). One turns on the lights for my lizard in the morning and another turns them off at the end of the day. As the days get longer and shorter, I need to go in and modify these two jobs and when they execute.

    In its current form, its not really a big deal. But I was thinking, "wouldn't it be cool to have the lights go on and off around about the same time the sun rises and sets?" I mean, this is what the lizard is used to anyways. This would also mean I wouldn't have to keep manually updating the cron jobs.

    So my theory is, write some Perl code to calculate the sun rise and sun set.

    Here's where things get a little muddy and unclear -

    One theory is to have a 3rd party script to handle modifying the lights on and off times directly in the cron job list. Maybe have this script run sometime between 2a-4a and it sets that day's times.

    Another thought was to just have this 3rd party script run between 2a-4a and have it setup a scheduled job (using the 'at' command). This means I wouldn't have to create a program to modify the cron job properties. My concern here is if the box reboots or loses power (which tends to happen about 30 days or so) the next 'at' job will be lost (or worse, the jobs for that day will be lost).

    -- --

    This was just something I'm playing around with and is just for giggles. Are there better/other ways to do this?

    And just in case: NO - VB is not an option (think Linux).
     
  2. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    Hmm... I think this answered most of my questions:

    http://www.drwren.com/ephem/

    Although I'm not comfortable not knowing how much mucking it does to the cron files. Which leaves me to maybe write my own in C/C++.
     
  3. a2vwnick

    a2vwnick VW Motorsports

    Joined:
    May 30, 2001
    Messages:
    547
    Likes Received:
    0
    Location:
    SoCal, CA
    you shouldn't have a problem editing the files in /var/spool/cron. every minute when cron runs, it checks the time stamp on those files and if they are new, cron will load them in place of the previous files. i would be cautious of the format, i can not remember off hand what the white space should be.
     

Share This Page