-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorganize.sh
140 lines (122 loc) · 3.59 KB
/
organize.sh
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/sh
##########################################################################
# Yet Another Monitor (YAMon)
# Copyright (c) 2013-present Al Caughey
# All rights reserved.
#
# This program organizes files in your data directory as per settings in
# config.file
#
# Updated:
# - May 23, 2015 - recreated this file
#
##########################################################################
d_baseDir=$(cd "$(dirname "$0")" && pwd)
_configFile="${d_baseDir}/config.file"
d_usageFileName="mac_data2.js"
_loglevel=1
_logFileName="monitor-*.log"
send2log(){
[ "$2" -ge "$_loglevel" ] && echo "$1"
}
organizeByYr(){
send2log "Organizing by year
>>> Be patient... as it may take several minutes for this process to complete!
" 2
for f in $datadir
do
local fn=$(echo "$f" | cut -d'/' -f5)
if [ "$fn" == "users.js" ] ; then
return
fi
local yr=$(echo "$fn" | cut -d'-' -f1)
local mo=$(echo "$fn" | cut -d'-' -f2)
local da=$(echo "$fn" | cut -d'-' -f3)
local rm=${mo#0}
local ry="$yr"
if [ "$da" -lt "$_ispBillingDay" ] ; then
rm=$(($rm-1))
if [ "$rm" == "0" ] ; then
rm=12
ry=$(($ry-1))
fi
fi
local rm=$(printf %02d $rm)
[ "$_loglevel" -eq "0" ] && send2log "Processing $fn... yr: $yr mo: $mo da: $da ($_ispBillingDay) -----> $ry-$rm" 0
send2log "Processing $fn" 2
dest="$savePath$ry"
[ ! -d "$dest" ] && mkdir -p "$dest"
$(mv -n "$f" "$dest")
done
}
organizeByYrMo(){
send2log "Organizing by year & month
>>> Be patient... as it may take several minutes for this process to complete!
" 2
for f in $datadir
do
local fn=$(echo "$f" | cut -d'/' -f5)
if [ "$fn" == "users.js" ] ; then
return
fi
local yr=$(echo "$fn" | cut -d'-' -f1)
local mo=$(echo "$fn" | cut -d'-' -f2)
local da=$(echo "$fn" | cut -d'-' -f3)
local rm=${mo#0}
local ry="$yr"
if [ "$da" -lt "$_ispBillingDay" ] ; then
rm=$(($rm-1))
if [ "$rm" == "0" ] ; then
rm=12
ry=$(($ry-1))
fi
fi
local rm=$(printf %02d $rm)
[ "$_loglevel" -eq "0" ] && send2log "Processing $fn... yr: $yr mo: $mo da: $da ($_ispBillingDay) -----> $ry-$rm" 0
send2log "Processing $fn" 2
dest="$savePath$ry/$rm"
[ ! -d "$dest" ] && mkdir -p "$dest"
$(mv -n "$f" "$dest")
done
}
send2log "
=== Organize data ===
" 2
if [ ! -f "$_configFile" ] ; then
send2log "*** Cannot find \`config.file\` in the following location:
>>> $_configFile
If you are using a different default directory (other than the one specified above),
you must edit lines 16-17 in this file to point to your file location.
Otherwise, check spelling and permissions." 0
exit 0
fi
send2log "Reading config.file --> $_configFile" 0
while read row
do
eval $row
done < $_configFile
#_dataDir="data3/"
_buDir="data-bu/"
savePath="${d_baseDir}/$_dataDir"
buPath="${d_baseDir}/$_buDir"
if [ "$_organizeData" -ne "0" ] ; then
send2log "Backing up $savePath to $buPath " 2
$(cp -a "$savePath" "$buPath")
fi
local datadir="${d_baseDir}/$_dataDir*.js"
send2log "Processing files: $datadir" 2
case $_organizeData in
(*"0"*)
send2log "_organizeData --> $_organizeData... nothing to do" 2
;;
(*"1"*)
organizeByYr
;;
(*"2"*)
organizeByYrMo
;;
esac
send2log "
*******************
**** Done ***
*******************" 2