Announcement

Collapse
No announcement yet.

[SOLVED] Running a task weekly...

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [SOLVED] Running a task weekly...

    Hello,
    I want to setup a task to run on my pc (a hard disk SMART check, with email notification in case of error).
    I set up a simple script to do that, and I want it to run once a week.
    The problem is that the PC isn't always on. So I can't just setup a cron job, because there isn't a time when the pc will surely be switched on on a given day. (i.e. if I set the task to run, say, at 11am every Sunday, the pc might be off at that time next Sunday...)
    I thought I might make a script to be run at boot, which checks a file that tells it when the next job was scheduled to occur; and if that time is passed, run the job and update the "next-run" file. This might work (if I can figure out how to work with dates within scripts) but it's not elegant. Is there a way to setup a cron job so that if that job should have occurred while the pc was off, then it is run at the next boot? I looked at the cron man page but couldn't find anything useful...

    #2
    Re: Running a task weekly...

    Originally posted by Quaxo76
    Hello,
    I want to setup a task to run on my pc (a hard disk SMART check, with email notification in case of error).
    I set up a simple script to do that, and I want it to run once a week.
    The problem is that the PC isn't always on. So I can't just setup a cron job, because there isn't a time when the pc will surely be switched on on a given day. (i.e. if I set the task to run, say, at 11am every Sunday, the pc might be off at that time next Sunday...)
    I thought I might make a script to be run at boot, which checks a file that tells it when the next job was scheduled to occur; and if that time is passed, run the job and update the "next-run" file. This might work (if I can figure out how to work with dates within scripts) but it's not elegant. Is there a way to setup a cron job so that if that job should have occurred while the pc was off, then it is run at the next boot? I looked at the cron man page but couldn't find anything useful...
    I am no expert on cron, but it looks like, as you suspect, you will need to set up a process that runs at system boot and coordinates with the cron output in such a way that it will do what the cron job normally does in case the last weekly task did not run.

    As for working with dates, you can probably store dates in integer format and compare the values using "-lt" or something like that in your script.

    Registered Linux User: #281828 | Kubuntu User: #22280

    Kubuntu 18.04 LTS
    Dell Precision Workstation T5500 (Xeon @ 2.13GHz x 2 / 12 GB RAM)

    Comment


      #3
      Re: Running a task weekly...

      Try anacron. See the anacron man page. To quote from the package description:
      Anacron (like `anac(h)ronistic') is a periodic command
      scheduler. It executes commands at intervals specified in days. Unlike cron,
      it does not assume that the system is running continuously. It can
      therefore be used to control the execution of daily, weekly and
      monthly jobs (or anything with a period of n days), on systems that
      don't run 24 hours a day. When installed and configured properly,
      Anacron will make sure that the commands are run at the specified
      intervals as closely as machine-uptime permits.
      It should be installed on your machine, already. At least, I don't remember installing it.

      Comment


        #4
        Re: Running a task weekly...

        Maybe this helps: > Using anacron ( from HOWTO : Cleaning old KDE thumbnails )


        About SMART

        There is a smart daemon (man smartd)
        DESCRIPTION
        smartd is a daemon that monitors the Self-Monitoring, Analysis and Reporting Technology (SMART) system built into many ATA-3 and later ATA, IDE and SCSI-3 hard drives.

        ...

        In addition to logging to a file, smartd can also be configured to send email warnings if problems are detected.

        ...
        Before you edit, BACKUP !

        Why there are dead links ?
        1. Thread: Please explain how to access old kubuntu forum posts
        2. Thread: Lost Information

        Comment


          #5
          Re: Running a task weekly...

          Aah, that looks like what the OP needs. I wasn't aware that anacron can do that. Thanks for the insightful information. 8)
          Registered Linux User: #281828 | Kubuntu User: #22280

          Kubuntu 18.04 LTS
          Dell Precision Workstation T5500 (Xeon @ 2.13GHz x 2 / 12 GB RAM)

          Comment


            #6
            Re: Running a task weekly...

            Sorry for the late reply. I didn't have time to work on the PC lately.
            Anyway... anacron is exactly what I needed! Thank you! I set up a simple script in /usr/local/bin and I configured anacrontab to run that script. Thanks again!

            Cristian

            Comment

            Working...
            X