-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect
executable file
·92 lines (87 loc) · 2.61 KB
/
collect
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
#!/bin/sh
############## wamba first index ##############
WAMBA_INI='10'
############## wamba last index ###############
WAMBA_END='19'
############### out files' target #############
OUT_TARGET=rodsadmin@torroja.dmt.upm.es:out_files/
################# locking #####################
IFS='
'
INPUT=$1
NAME=`echo $INPUT | sed 's|/||g'`
SCRIPTNAME=`basename $0`
PIDFILE=${PWD}/${SCRIPTNAME}.{$NAME}.pid
BASEDIR=${PWD}
machine=''
###############################################
################# functions ###################
collect()
{
for line in `find $1 ${pattern[@]} -type f`;do
size=`du -bh "$line" | awk '{print $1}'`
# cdate=`du --time=ctime "$line" | awk '{print $2 " " $3}'`
mtime=`du --time "$line" | awk '{print $2 " " $3}'`
# mtime=`stat -c %y "$line" | cut -d : -f 1,2`
dir=`dirname "$line"`
file=`basename "$line"`
if [ $size '!=' 0 ]; then
if [ "$dir" != "$current_dir" ]; then
current_dir=$dir
echo "$size|$mtime|$machine$dir/$file"
else
if [ -f "$line" ]; then
echo "$size|$mtime|$file"
fi
fi
fi
done
}
################# main ####################
if [ $# != 3 ] && [ $# != 5 ]; then
echo "usage: collect <absolute-path> -h <hostname> -p [search-pattern]"
echo "absolute-path - A Linux path beggining with '/'."
echo "search-pattern - string after '-name' operation in 'find' command. If not specified, indexing all files."
echo "hostname - name of the folder at the top of the RODS tree."
exit 255
fi
if [ "$2" == "-p" ]; then
declare -a pattern
pattern[0]="-name"
pattern[1]=$3
fi
if [ "$4" == "-p" ]; then
declare -a pattern
pattern[0]="-name"
pattern[1]=$5
fi
if [ "$2" == "-h" ]; then
machine=$3
fi
if [ "$4" == "-h" ]; then
machine=$5
fi
############### locking ###################
if [ -f ${PIDFILE} ]; then
#verify if the process is actually still running under this pid
OLDPID=`cat ${PIDFILE}`
RESULT=`ps -ef | grep ${OLDPID} | grep ${SCRIPTNAME}`
if [ -n "${RESULT}" ]; then
echo "Script already running! Exiting"
exit 255
fi
fi
PID=`ps -ef | grep ${SCRIPTNAME} | head -n1 | awk ' {print $2;} '`
echo ${PID} > ${PIDFILE}
############# critical section ############
# if [ -f $BASEDIR/$out_file ]; then
# rm -f $BASEDIR/$out_file.out
# fi
# echo `date` - "Starting 'collect' for "$NAME"..." >> $BASEDIR/logs/$NAME.log
collect $INPUT
# echo `date` - "Finished 'collect'." >> $BASEDIR/logs$INPUT.log
######### end of critical section #########
if [ -f ${PIDFILE} ]; then
rm ${PIDFILE}
fi
###########################################