You are not logged in.

#51 2012-02-26 21:41:48

kekules_dream
Member
Registered: 2009-05-19
Posts: 102

Re: Cronwhip - no more missed cronjobs

It looks like the default setup may take care of missed cronjobs now.  From ANACRON(8):

Anacron  is  used  to  execute commands periodically, with a frequency specified in days.  Unlike cron(8), it does not assume that the machine is running continuously.  Hence, it can be used on machines that are not running 24 hours a day to control regular jobs as daily, weekly, and monthly jobs.

Regardless, thank you for making cronwhip.  I have used it for a long time.

Offline

#52 2012-02-27 01:09:03

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Cronwhip - no more missed cronjobs

Damn, I just rewrote it in Python and finally added a daemon. I should have checked this thread first.

*sigh*

edit: hmm, it seems that anacron can only runs tasks once a day, and that it has more deps than crond...

Last edited by Xyne (2012-02-27 01:31:26)


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#53 2012-03-25 04:11:38

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Cronwhip - no more missed cronjobs

Why do I get

Traceback (most recent call last):
  File "/usr/bin/cronwhip", line 5, in <module>
    main_original()
  File "/usr/lib/python3.2/site-packages/cronwhip.py", line 334, in main_original
    run_job(job)
  File "/usr/lib/python3.2/site-packages/cronwhip.py", line 199, in run_job
    run_cmd(cmd, inp)
  File "/usr/lib/python3.2/site-packages/cronwhip.py", line 222, in run_cmd
    sys.stderr.write('command exited with %d: %s\n' % (e, str(cmd)))
NameError: global name 'sys' is not defined

?

Offline

#54 2012-03-25 09:05:58

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Cronwhip - no more missed cronjobs

It should be fixed now. Keep an eye on the output though, because that block is only invoked when one of the cronjobs exits with non-zero status.

Last edited by Xyne (2012-03-25 09:51:58)


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#55 2012-04-08 21:13:28

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Cronwhip - no more missed cronjobs

How about

command exited with 127: ['/bin/sh', 'ID=sys-hourly', '/usr/sbin/run-cron', '/etc/cron.hourly']
Traceback (most recent call last):
  File "/usr/bin/cronwhip", line 5, in <module>
    main_original()
  File "/usr/lib/python3.2/site-packages/cronwhip.py", line 339, in main_original
    run_job(job)
  File "/usr/lib/python3.2/site-packages/cronwhip.py", line 200, in run_job
    run_cmd(cmd, inp)
  File "/usr/lib/python3.2/site-packages/cronwhip.py", line 224, in run_cmd
    if pin:
NameError: global name 'pin' is not defined

I get with cronwhip 2012.4-1?

Offline

#56 2012-04-09 16:46:32

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Cronwhip - no more missed cronjobs

@karol
That particular error should be fixed now, but it was inside an exception block, so keep your eye on the output.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#57 2012-04-28 18:53:48

Lockheed
Member
Registered: 2010-03-16
Posts: 1,527

Re: Cronwhip - no more missed cronjobs

If in cron, there are jobs being run every hour, and the computer was off for 10 hours, will cronwhip run this job once, or 10 times?

Offline

#58 2012-04-28 20:27:18

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Cronwhip - no more missed cronjobs

Lockheed wrote:

If in cron, there are jobs being run every hour, and the computer was off for 10 hours, will cronwhip run this job once, or 10 times?

Just once: https://bbs.archlinux.org/viewtopic.php … 00#p693200

Offline

#59 2012-04-29 06:57:55

Lockheed
Member
Registered: 2010-03-16
Posts: 1,527

Re: Cronwhip - no more missed cronjobs

I have an issue running this:

Traceback (most recent call last):
  File "/usr/bin/cronwhip", line 5, in <module>
    main_original()
  File "/usr/lib/python3.2/site-packages/cronwhip.py", line 322, in main_original
    down,up = get_last_shutdown_interval_from_wtmp(wtmp_paths)

Also, is it possible to exclude some jobs from being run? Or run only items from the non-root crontab?

Offline

#60 2012-04-29 16:15:25

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Cronwhip - no more missed cronjobs

@Lockheed
Post the full error message. You've omitted the exception, so I have no idea what happened.

If you only want to run some cronjobs, use the dry-run command-line options and grep to filter the command list.
Cronwhip runs the jobs in the crontab of the user that runs cronwhip. if you run it as root, it runs roots cronjobs. If you run it as a regular user, it runs that user's cronjobs.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#61 2012-04-29 17:48:58

Lockheed
Member
Registered: 2010-03-16
Posts: 1,527

Re: Cronwhip - no more missed cronjobs

$ cronwhip -n
Traceback (most recent call last):
  File "/usr/bin/cronwhip", line 5, in <module>
    main_original()
  File "/usr/lib/python3.2/site-packages/cronwhip.py", line 322, in main_original
    down,up = get_last_shutdown_interval_from_wtmp(wtmp_paths)
TypeError: 'NoneType' object is not iterable

Does it mean cronwhip run as root will run all the jobs from root + user, or just root?

Offline

#62 2012-04-29 18:38:46

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Cronwhip - no more missed cronjobs

Lockheed wrote:

Does it mean cronwhip run as root will run all the jobs from root + user, or just root?

Just root. It uses "crontab -l" to determine cronjobs.

For the ValueError, it's failing to determine the last shutdown interval. Do you not have the /var/log/wtmp* log files on your system?


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#63 2012-04-29 18:40:10

Lockheed
Member
Registered: 2010-03-16
Posts: 1,527

Re: Cronwhip - no more missed cronjobs

Yes.

Offline

#64 2012-04-29 21:51:13

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Cronwhip - no more missed cronjobs

When trying to upgrade cronwhip to version 2012.4.29-1 I get an error:

error: failed to commit transaction (conflicting files)
cronwhip: /usr/lib/python3.2/site-packages/__pycache__/cronwhip.cpython-32.pyc exists in filesystem
Errors occurred, no packages were upgraded.

Can I just remove this file?

Last edited by karol (2012-04-29 21:52:02)

Offline

#65 2012-04-30 18:31:52

Lockheed
Member
Registered: 2010-03-16
Posts: 1,527

Re: Cronwhip - no more missed cronjobs

I installed latest cronwhip update and still I am getting similar error message:

$ cronwhip -n
error: failed to last detect shutdown interval
       (missing wtmp files or incomplete output from "last -x")

Offline

#66 2012-04-30 22:12:16

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Cronwhip - no more missed cronjobs

@karol
yes

@Lockheed
As the message says, you're either missing /var/log/wtmp* files or there's something weird with the output of "last -x" (which depends on those files). What's the output of "locate wtmp"?


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#67 2012-04-30 22:37:48

Lockheed
Member
Registered: 2010-03-16
Posts: 1,527

Re: Cronwhip - no more missed cronjobs

$ locate wtmp
/usr/share/man/man3/logwtmp.3.gz
/usr/share/man/man3/updwtmp.3.gz
/usr/share/man/man3/updwtmpx.3.gz
/usr/share/man/man5/wtmp.5.gz
/var/log/wtmp
/var/log/wtmp.1

Offline

#68 2012-05-01 22:23:33

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Cronwhip - no more missed cronjobs

Ok, I found a bug that might be causing this. Update to the latest version in my repo and let me know if it works.
I've also changed the way it handles missing shutdown times. It will now print a warning and then run all cronjobs once.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#69 2012-08-28 09:22:50

spitfires
Member
Registered: 2012-08-28
Posts: 1

Re: Cronwhip - no more missed cronjobs

Excellent - many thanks Xyne.  Just what I was looking for. 

I use the old cronwhip.pl which is sufficient for my needs.  I've modified it to add a "user" parameter to allow cronwhip to process the crontab of users other than the logged-in user.  (I run it on a dev server as root but need to run the missed crontab for apache).

A simple fix which uses the -u parameter to crontab

--- /tmp/cronwhip.pl	Tue Aug 28 10:14:09 2012
+++ /tmp/cronwhip.pl-2012.5.1	Sun May 01 01:59:02 2011
@@ -16,9 +16,6 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-# Modified by Spitfires to add --user parameter  (Aug 2012)
-#
-
 use warnings;
 use strict;
 use POSIX qw(strftime);
@@ -45,16 +42,12 @@
   -n, --dry-run  Print cronjobs that would be run without running them.
       --help     Display this help message.
   -v, --verbose  Run cronwhip in verbose mode.
-  -u, --user     Use crontab for this user.
 
 HELP
   system("fmt -s <<HELP\n$help\nHELP\n");
 }
 my $dryrun = ($args =~ m/(?:^|\s)-(?:n|-dry-run)(?:$|\s)/) ? 1 : 0;
 my $verbose = ($args =~ m/(?:^|\s)-(?:v|-verbose)(?:$|\s)/) ? 1 : 0;
-my $user = ($args =~ m/(?:^|\s)-(?:u|-user)(?:$|\s)/) ? 1 : 0;
-my $userac = ($args =~ m/(?:^|\s)-(?:u|-user)\s(.+)(?:$|\s)/) ? $1 : "";
 
 my $last_shutdown = `last -x | grep -m 1 shutdown`;
 my ($days,$hours,$mins) = ($last_shutdown =~ m/\((?:(\d+)\+)?(\d\d):(\d\d)\)\s*$/);
@@ -87,7 +80,7 @@
 # print strftime("%F %T%n", localtime($last)); # last shutdown
 # print strftime("%F %T%n", localtime($now)); # current time
 
-my $cronjobs = ($user == 1) ?`crontab -l -u $userac` : `crontab -l`;
+my $cronjobs = `crontab -l`;
 
 while (my ($key, $value) = each (%SPECIALS))
 {

Offline

#70 2013-07-06 10:08:30

sudoku
Member
Registered: 2012-10-31
Posts: 96

Re: Cronwhip - no more missed cronjobs

Can some cronjobs be excluded from cronwhip, e.g. some cronjob like

00 23 * * * /bin/echo "It's 11pm. Please go to bed"

or similar? It wouldn't make any sense running this cronjob at 9am when the computer is turned on again.

Offline

#71 2013-07-06 11:37:29

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Cronwhip - no more missed cronjobs

I have added an option ("--skip") that accepts a file path. Add the commands to be skipped to that file, e.g.
skip_cmds.txt

/bin/echo "It's 11pm. Please go to bed"

then run

cronwhip --skip skip_cmds.txt -n

to test if it works. Let me know if it does. I haven't tested it myself because I no longer have any cronjobs but the change was trivial

You'll need to provide your own service file. Take the default one and just add "--skip /path/to/your/file" to the "ExecStart" line and save it to /etc/systemd/system.


Incidentally, if you know even a little bit of Python then you should be able to write your own scripts using the cronwhip module in this package. It's quite simple.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#72 2013-11-22 09:41:21

lunarjar
Member
Registered: 2013-02-13
Posts: 11

Re: Cronwhip - no more missed cronjobs

I had a cron for 7am, but my laptop was suspended, when I woke it up at 8.30am the cron didn't run. How can I fix it/debug what is going on?

Offline

#73 2013-11-23 17:10:32

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Cronwhip - no more missed cronjobs

The code gets the last shutdown time from the output of "last". To run cronjobs after suspension it would need a way to detect suspension. I don't have any idea how to do that right now.

If there is some programmatically reliable way then I can include it in the code. Otherwise I can add options to run cronjobs in a user-specified interval and let users write their own suspend and resume wrapper scripts (i.e. save the time before suspending, pass it to cronwhip upon resuming).

Update

I have now added options for configuring the interval. See "cronwhip -h" for details.

Last edited by Xyne (2013-11-23 20:28:35)


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#74 2013-11-28 22:55:00

Lockheed
Member
Registered: 2010-03-16
Posts: 1,527

Re: Cronwhip - no more missed cronjobs

I have been using itcronwhip since quite some time, but since several months it no longer starts:

cronwhip.service - Run missed cronjobs with cronwhip.
   Loaded: loaded (/usr/lib/systemd/system/cronwhip.service; enabled)
   Active: failed (Result: exit-code) since Thu 2013-11-28 23:52:30 CET; 3s ago
  Process: 3576 ExecStart=/usr/bin/cronwhip (code=exited, status=1/FAILURE)
 Main PID: 3576 (code=exited, status=1/FAILURE)

I tried reinstalling it, but it changed nothing.

Offline

#75 2013-11-28 23:21:07

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Cronwhip - no more missed cronjobs

Read the rest of the output that you omitted from your post. The third line down will tell you why it failed (no crontab for root).

If you have no crontab, then cronwhip won't work.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

Board footer

Powered by FluxBB