-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
executable file
·40 lines (32 loc) · 941 Bytes
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env ruby
require '/etc/autocleaner/config.rb'
################################################################################
# Functions
################################################################################
def sanity_check!(folders)
folders.each{|x|
if x[:folder].nil? then raise ":folder not defined, source: #{x}" end
if x[:days].nil? then raise ":days not defined, source: #{x}" end
if x[:glob].nil? then x[:glob] = "*" end
}
end
################################################################################
# Main
################################################################################
folders = Config::FOLDERS
sanity_check!(folders)
folders.each{|x|
print("Processing: #{x}\n")
pid = Process.spawn(
{},
["find", "find"],
"-mtime", "+"+x[:days].to_s,
"-type", "f",
"-name", x[:glob],
"-print",
"-delete",
:chdir=>x[:folder],
)
Process.wait pid
}
print("Done.\n")