scron 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.md +23 -0
- data/README.md +60 -0
- data/scron.rb +8 -2
- data/scron_test.rb +1 -1
- metadata +37 -52
data/LICENSE.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2012, Hugh Bien
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
5
|
+
are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
Redistributions of source code must retain the above copyright notice, this list
|
8
|
+
of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
Redistributions in binary form must reproduce the above copyright notice, this
|
11
|
+
list of conditions and the following disclaimer in the documentation and/or
|
12
|
+
other materials provided with the distribution.
|
13
|
+
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
15
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
16
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
17
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
18
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
19
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
20
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
21
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
22
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
23
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
Description
|
2
|
+
===========
|
3
|
+
|
4
|
+
Scron is a scheduler for laptops/machines which aren't on 24/7.
|
5
|
+
|
6
|
+
|
7
|
+
Installation
|
8
|
+
============
|
9
|
+
|
10
|
+
% gem install scron
|
11
|
+
|
12
|
+
Then configure cron to run it. I recommend every 2 hours, but you can put any
|
13
|
+
interval here:
|
14
|
+
|
15
|
+
% crontab -e
|
16
|
+
0 */2 * * * scron -r
|
17
|
+
|
18
|
+
|
19
|
+
Usage
|
20
|
+
=====
|
21
|
+
|
22
|
+
Configure jobs in `$HOME/.scron` (`scron -e` to edit). This example means run
|
23
|
+
`cmd arg1 arg2` at least once every 30 days:
|
24
|
+
|
25
|
+
30d cmd arg1 arg2
|
26
|
+
|
27
|
+
You can also specify lower bounds like day of week (Su, Mo, Tu, We, Th, Fr, Sa),
|
28
|
+
day of month (23rd), or day of year (4/15):
|
29
|
+
|
30
|
+
Mo,Fr cmd1
|
31
|
+
1st,23rd cmd2
|
32
|
+
4/15 cmd3
|
33
|
+
|
34
|
+
`cmd1` will attempt to run on Monday and Friday. If your machine is off the
|
35
|
+
entire day, it will run as soon as possible. Here's an example timeline:
|
36
|
+
|
37
|
+
* Mo: machine is off, nothing happens
|
38
|
+
* Tu: machine is on, cmd1 runs to make up for Monday
|
39
|
+
* We: already ran, nothing happens
|
40
|
+
* Th: already ran, nothing happens
|
41
|
+
* Fr: machine is on, cmd1 runs
|
42
|
+
|
43
|
+
|
44
|
+
Notes
|
45
|
+
=====
|
46
|
+
|
47
|
+
An exit status of 0 is considered a success. Anything else is considered a
|
48
|
+
failure and scron will attempt to re-run it again in 2 hours.
|
49
|
+
|
50
|
+
`$HOME/.scrondb` keeps the timestamps of the last run commands.
|
51
|
+
|
52
|
+
`$HOME/.scronlog` has the stdout, timestamps, and exit status of last
|
53
|
+
scheduled commands.
|
54
|
+
|
55
|
+
|
56
|
+
License
|
57
|
+
=======
|
58
|
+
|
59
|
+
Copyright 2012 Hugh Bien - http://hughbien.com.
|
60
|
+
Released under BSD License, see LICENSE.md for more info.
|
data/scron.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'date'
|
2
2
|
|
3
3
|
class Scron
|
4
|
-
VERSION = '1.0.
|
4
|
+
VERSION = '1.0.1'
|
5
5
|
SCHEDULE_FILE = "#{ENV['HOME']}/.scron"
|
6
6
|
HISTORY_FILE = "#{ENV['HOME']}/.scrondb"
|
7
7
|
LOG_FILE = "#{ENV['HOME']}/.scronlog"
|
@@ -22,7 +22,7 @@ class Scron
|
|
22
22
|
|
23
23
|
logger = []
|
24
24
|
overdue.each do |schedule|
|
25
|
-
output =
|
25
|
+
output = safe_cmd(schedule.command)
|
26
26
|
logger << "=> #{now.strftime(History::FORMAT)} #{schedule.command} (#{$?.to_i})"
|
27
27
|
logger << output unless output == ''
|
28
28
|
scron.history.touch(schedule.command) if $?.to_i == 0
|
@@ -40,6 +40,12 @@ class Scron
|
|
40
40
|
end
|
41
41
|
|
42
42
|
private
|
43
|
+
def self.safe_cmd(command)
|
44
|
+
`#{command}`
|
45
|
+
rescue StandardError => error
|
46
|
+
error.to_s
|
47
|
+
end
|
48
|
+
|
43
49
|
def self.read(filename)
|
44
50
|
File.exist?(filename) ? File.read(filename) : ''
|
45
51
|
end
|
data/scron_test.rb
CHANGED
metadata
CHANGED
@@ -1,84 +1,69 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: scron
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 0
|
10
|
-
version: 1.0.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Hugh Bien
|
14
9
|
autorequire:
|
15
10
|
bindir: .
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-05-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: minitest
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :development
|
33
|
-
|
34
|
-
|
35
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Run commands at scheduled intervals. If an interval is missed, the command
|
31
|
+
will be run as soon as possible.
|
32
|
+
email:
|
36
33
|
- hugh@hughbien.com
|
37
|
-
executables:
|
34
|
+
executables:
|
38
35
|
- scron
|
39
36
|
extensions: []
|
40
|
-
|
41
37
|
extra_rdoc_files: []
|
42
|
-
|
43
|
-
files:
|
38
|
+
files:
|
44
39
|
- scron.rb
|
45
40
|
- scron_test.rb
|
41
|
+
- README.md
|
42
|
+
- LICENSE.md
|
46
43
|
- scron
|
47
44
|
- ./scron
|
48
45
|
homepage: https://github.com/hughbien/scron
|
49
46
|
licenses: []
|
50
|
-
|
51
47
|
post_install_message:
|
52
48
|
rdoc_options: []
|
53
|
-
|
54
|
-
require_paths:
|
49
|
+
require_paths:
|
55
50
|
- lib
|
56
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
52
|
none: false
|
58
|
-
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
|
62
|
-
|
63
|
-
- 0
|
64
|
-
version: "0"
|
65
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
58
|
none: false
|
67
|
-
requirements:
|
68
|
-
- -
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
hash: 23
|
71
|
-
segments:
|
72
|
-
- 1
|
73
|
-
- 3
|
74
|
-
- 6
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
75
62
|
version: 1.3.6
|
76
63
|
requirements: []
|
77
|
-
|
78
64
|
rubyforge_project:
|
79
|
-
rubygems_version: 1.8.
|
65
|
+
rubygems_version: 1.8.23
|
80
66
|
signing_key:
|
81
67
|
specification_version: 3
|
82
68
|
summary: Scheduler for laptops/machines which aren't on 24/7
|
83
69
|
test_files: []
|
84
|
-
|