-
Notifications
You must be signed in to change notification settings - Fork 14
/
flist-reconcile.sh
70 lines (50 loc) · 1.73 KB
/
flist-reconcile.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
#!/bin/bash5
debugg=0
if [ $debugg -gt 0 ]; then
echo "$(date) Running flist 1st JIC"
time flist
fi
# failexit.mrg
function failexit () {
echo '! Something failed! Code: '"$1 $2" # code # (and optional description)
exit $1
}
todel=/tmp/todel-flist.txt
>$todel # clearit
# if flist with no tar, del
declare -i fl tr # integer
fl=$(ls flist* |wc -l |awk '{print $1}')
tr=$(ls *tar* |grep -v flist |wc -l |awk '{print $1}')
echo "Flists: $fl -- Tars: $tr"
[[ $fl == $tr ]] && failexit 0 "Flists match tars, evyting OK"
# regular array
declare -a flists=$(ls flist*)
for c in ${flists[@]}; do
proc1=$(basename $c .txt) # strip .txt from end
proc2=${proc1:7} # easy strip flist--
if [ $debugg -gt 0 ]; then
[ -e $proc2.tar* ] && echo "MATCH $c" || echo "NOTMATCH $c"
fi
# [ -e $proc2.tar* ] || echo "NOTMATCH $c"
[ -e $proc2.tar* ] || echo "$c" >> $todel
done
echo "$(wc -l $todel) - hanging FLIST files to delete - Enter to process NON-INTERACTIVELY or ^C"
read
while read inline; do
[ "$inline" = "" ] && break
ls -l "$inline" |awk '{print "Size:"$5" Date: "$6" "$7" "$8" "$9}' #|column -t
/bin/rm -v "$inline"
done < $todel
# for some reason RM -i not working :(
# Cleanup
# /bin/rm $todel
exit;
NOTE MAC OSX wc -l also prints filename, thats why we need 1st field only!
REF: https://tldp.org/LDP/abs/html/string-manipulation.html
la|awk '{print "Size:"$5" Date: "$6" "$7" "$8" "$9}' |column -t
Size:35077 Date: Jan 15 11:12 flist--bkp-home-dave-test-p2300m-deepin-sda6.txt
basename bkp-home--NORZ--p2300m-ultimate--20200626.tar1.tar .tar1.tar
bkp-home--NORZ--p2300m-ultimate--20200626
missing tar: flist--bkp-home--fryserverantix19--NORZ--20210303.txt
matches: flist--bkp-home-p2300m-deepin-sda6.txt
01234567