-
Notifications
You must be signed in to change notification settings - Fork 0
/
iterator
34 lines (33 loc) · 877 Bytes
/
iterator
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
#!/bin/bash
#Usage : iterate path/to/directory/to/scan path/to/database path/to/directory/to/scan"/"
iterate()
{
if [ $# -lt 2 ] ; then
echo "Not enough arguments: 3 are requested"
echo "Usage : iterate path/to/directory/to/scan path/to/database path/to/directory/to/scan"/""
exit 1
fi
if [ ! -d "$1" ] ; then
echo "1st argument must be a directory"
exit 1
fi
if [ ! -f "$2" ] ; then
echo "2nd argument must be a file"
exit 1
fi
for file in "$1"/*
do
if [ -d "$file" ] ; then
#echo "subdirectory '${file##*/}' found"
tmp=$(stat -c '%n %F %A %s bytes %y' "$file")
echo ${tmp#$3} | awk '{print $1}' >> "$2"
#recursively call the function for subdir
iterate "$file" "$2" "$3"
else
#echo "${file##*/}"
#log all the metadata into the temp file
tmp=$(stat -c '%n %F %A %s bytes %y' "$file")
echo ${tmp#$3} >> "$2"
fi
done
}