Setup Anacron in WebGUI?

  • I set up snapraid 4.0 yesterday to protect my data. Simple question:
    How can I setup a anacron-job (weekly/monthly) in the WebGUI? Is it possible in general?
    I know how to do it on the CLI, but wanted to know if it's working in the GUI too ;)
    My NAS isn't running the whole day, because of that I find a anacron job for snapraid better.

  • My understanding is that if something is added to cron that anacron will run all the cron items if anacron determines it has not been done. anacron looks at the date inside the files of /var/spool/anacron/cron.daily or cron.weekly or cron.monthly


    So if you were to add something through the OMV GUI user defined cron jobs, anacron should pick it up and go with it, so long as OMV adds the task to the /etc/cron.daily .weekly or .monthly directories.


    If it does not, the shell script, or symbolic link to the script, should be added to the /etc/cron.daily .weekly or .monthly directories.


    EDIT: Continued next post.

  • I had things to take care of and had not finished about anacron.


    /etc/anacrontab is the file that anacron works from, it runs at boot and from cron as well from the /etc/cron.daily, .weekly .monthly directories from file 0anacron . 0anacron updates the date in files /var/spool/anacron/cron.daily .weekly .monthly to the date anacron ran.


    anacrontab should pick up the OMV user defined tasks.


    To check this try the following user defined task. Set it up in the OMV GUI cron jobs.


    Set the time to run at a time the server should be off. I chose 3:17 in the morning. cron should only run this once each day at 3:17 in the morning. The command;

    Code
    echo $(date +\%b\ \%d\ \%T\ )"Solo815 Start: /etc/cron.d/openmediavault-userdefined time in /etc/cron.d set to 03:17 other time anacron ran "$0 >> /var/log/syslog

    should put the above entry in the syslog file, or it will post an error in the syslog.


    EDIT: 25Sep13-16:25 Changed the above code line a second time - previous posted error in syslog - this one works - end EDIT


    I'm still learning the differences between the shells. Either way an entry should be readable from the OMV GUI view syslog. If the time of the log entry does not match 3:17 then anacron ran it at the time of the syslog entry. If the times match then cron ran it.


    While on the topic of cron/anacron I don't like the fact that they choose to run monthly files every thirty days, rather than the last day of the month. So I found this tidbit to solve it, but I can't recall where. Edit the monthly portion of the /etc/crontab file to look like this;

    Code
    47 03 28-31 * *       root    ( cd / && [ "$(date +\%d '-d tomorrow')" = "01" ] && run-parts --report /etc/cron.monthly )


    this will check on the 28th through the 31st to see if tomorrow is the 1st and if so it will run, if tomorrow is not the 1st then it will not run. anacron though may foul up the works here as I have yet to totally figure out how to get anacron and cron to play nice together (working it on my Pi). Since my OMV is on 24/7 I want cron to do most of the work. And I only want anacron to kick in when OMV has been off due to electrical or maintenance issues.


    Hope this helps.

  • The cron job wasn't running at all, because my Server was off during cron-execute time (05:24 in the morning). Another cron job was running at the specified time (03:00 in the morning) if i wake up the PC via rtcwake, but this is not a solution. Running the jobs manually via the "Play"-Button in OMV works.


    cron job from 03:00 executed. NAS was running, because of rtcwake at 02:45

    Code
    Sep 22 03:00:01 hoppetz /USR/SBIN/CRON[4040]: (root) CMD (/var/lib/openmediavault/cron.d/userdefined-b5bd4ebd-e8e8-4a7b-b0e9-025899d60317 >/dev/null 2>&1)


    the other cron job wasn't executed. No entry for it in syslog


    I just want to run jobs every day, week and month.If the NAS is off at the specified time, it should run the next time the NAS in online.
    Volker says:

    Zitat

    Anacron executes the cron-jobs at startup automatically if the cron-job was missing to be executed while the system was down. Please reopen this report if required and specify your requirements more detailed.


    ^^^ see http://bugtracker.openmediavault.org/view.php?id=851
    But anacron don't run the jobs from cron (if NAS was off at cron-execution time), at least for me.
    Can you guys please verify that? Thx
    I'll reopen the bug-report, if it is not working for you also.

  • Solo,


    I apologize as I still have an error some where in the code above, apparently with the date somehow. It works from the CLI - obviously I still do not understand the differences in the shells.


    Though the addition does create an error;

    Code
    Sep 22 04:38:12 omvserver /USR/SBIN/CRON[30747]: (CRON) error (grandchild #30748 failed with exit status 1)

    which shows by the time stamp that anacron ran it.


    This works from the CLI but I don't know if it will from the user defined cron;

    Code
    logger -f /var/log/syslog "Start: /etc/cron.d/openmediavault-userdefined set to run at 03:17 if entry time other - anacron ran"


    which should show this entry in the syslog

    Code
    Sep 22 17:05:55 omvserver logger: Start: /etc/cron.d/openmediavault-userdefined set to run at 03:17 if entry time other - anacron ran


    So it appears to me that anacron is picking up the tasks and running them as it should.

  • that doesn't work for me at all. I have NO entries about cron jobs in the logs, which were executed by anacron if the PC was offline at the specified cron-time
    I hope you understand :)
    my /etc/crontab


    /etc/cron.d/anacron

    Code
    # /etc/cron.d/anacron: crontab entries for the anacron package
    
    
    SHELL=/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    
    
    30 7    * * *   root    test -x /etc/init.d/anacron && /usr/sbin/invoke-rc.d anacron start >/dev/null


    /etc/cron.d/openmediavault-userdefined

    Code
    SHELL=/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    # m h dom mon dow user    command
    5 3 * * * root /var/lib/openmediavault/cron.d/userdefined-b5bd4ebd-e8e8-4a7b-b0e9-025899d60317 | mail -s "Cron - snapraid diff check mit Mail-Ausgabe" -a "From: Cron Daemon <root>" root >/dev/null 2>&1
    24 4 * * * root /var/lib/openmediavault/cron.d/userdefined-d59f8f4d-fd88-45b6-a6eb-2c39b57c6dc5 | mail -s "Cron - test anacron 2" -a "From: Cron Daemon <root>" root >/dev/null 2>&1
    0 6 * * * root /var/lib/openmediavault/cron.d/userdefined-9d2937fd-67d4-4722-bf2a-8fe9b29775f5 >/dev/null 2>&1


    here's the part of the log: (grep cron /var/log/syslog)

    Code
    Sep 24 18:25:21 hoppetz anacron[1602]: Anacron 2.3 started on 2013-09-24
    Sep 24 18:25:22 hoppetz anacron[1602]: Will run job `cron.daily' in 5 min.
    Sep 24 18:25:22 hoppetz anacron[1602]: Jobs will be executed sequentially
    Sep 24 18:25:30 hoppetz /usr/sbin/cron[1664]: (CRON) INFO (pidfile fd = 3)
    Sep 24 18:25:30 hoppetz /usr/sbin/cron[1665]: (CRON) STARTUP (fork ok)
    Sep 24 18:25:31 hoppetz /usr/sbin/cron[1665]: (CRON) INFO (Running @reboot jobs)
    Sep 24 18:30:21 hoppetz anacron[1602]: Job `cron.daily' started
    Sep 24 18:30:21 hoppetz anacron[2908]: Updated timestamp for job `cron.daily' to 2013-09-24


    a executed cron-job if the PC is online looks like this:

    Code
    Sep 23 16:05:01 hoppetz /USR/SBIN/CRON[27412]: (root) CMD (/var/lib/openmediavault/cron.d/userdefined-b5bd4ebd-e8e8-4a7b-b0e9-025899d60317 | mail -s "Cron - snapraid diff check mit Mail-Ausgabe" -a "From: Cron Daemon <root>" root >/dev/null 2>&1)
    Sep 23 16:08:35 hoppetz postfix/smtp[27812]: 0F9391630: replace: header Subject: Cron <root@hoppetz> /var/lib/openmediavault/cron.d/: Subject: Cron <root@hoppetz> /var/lib/openmediavault/cron.d/userdefined-b5bd4ebd-e8e8-4a7b-b0e9-025899d60317 | mail -s "Cron - snapraid diff check mit Mail-Ausgabe" -a "From: Cron Daemon <root>" root >/dev/null 2>&1 [hoppetz]


    or

    Code
    Sep 23 20:00:01 hoppetz /USR/SBIN/CRON[5657]: (root) CMD (/var/lib/openmediavault/cron.d/userdefined-9d2937fd-67d4-4722-bf2a-8fe9b29775f5 >/dev/null 2>&1)
    Sep 23 20:00:01 hoppetz logger: Start: /etc/cron.d/openmediavault-userdefined set to run at 20:00 if entry time other - anacron ran


    I hope someone can help me. How long after the systemstart are the pending cron-jobs executed by anacron?
    For me, anacron doesn't run any cron-job if the PC was offline at the execution-time of the cron-job. It is not about cron.daily, cron. weekly and so on, only if cron jobs are executed by anacron if the PC was offline.
    Thx 8-)

  • Solo,


    Sorry have not go back to you on this, life has a funny way of getting in the way of life. I reedited the first post with a corrected date setup that does work. I feel pretty stupid as I had not noticed the "Test" option in the cron jobs.


    Will post more later.


    Take Care & Enjoy.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!