Project

General

Profile

1
#!/bin/sh
2
#This script will send a buildIndex command to 
3
#remote metacat with docid parameter. Then metacat will build index for this docid.
4
#This script will have one argument - it is a text file name which contains docid list.
5
#The text file will look like
6
#nceas.1.1
7
#nceas.2.1
8
#nceas.3.1
9

    
10
if  [ $# -ne 1 ]
11
 then
12
    echo "USAGE: $0 docidfile"
13
    exit 1
14
fi 
15
echo 'Please type metacat url (It should look like "http://pacific.msi.ucsb.edu:8080/knb/metacat")'
16
read metacatBaseURL
17
echo 'Please type KNB user name (It should look like "uid=tao,o=NCEAS,dc=ecoinformatics,dc=org")'
18
read username
19
echo 'Please type password'
20
read password
21
date
22
#login to metacat
23
loginurl="$metacatBaseURL?action=login&username=$username&password=$password"
24
wget -q -O - --save-cookies cookies --keep-session-cookies "$loginurl"
25

    
26
suffix="?action=buildindex"
27
metacatURL="$metacatBaseURL$suffix"
28

    
29
FILE=$1
30
# make sure file exist and readable
31
if [ ! -f $FILE ]; then 
32
  	echo "$FILE : does not exists"
33
  	exit 1
34
elif [ ! -r $FILE ]; then
35
  	echo "$FILE: can not read"
36
  	exit 2
37
fi
38

    
39

    
40
index=0
41
length=3
42
# read $FILE using the file descriptors
43
exec 3<&0
44
exec 0<$FILE
45
while read line
46
do
47
    if [ "$line" != "" ]
48
    then
49
      # construct metacat with given length of docid
50
      metacatURL="$metacatURL&docid=$line"
51
      index=`expr $index + 1`
52
	    if [ $index -eq $length ]
53
	    then
54
	       echo "here is url $metacatURL"
55
	       wget -q -O - --load-cookies cookies "$metacatURL"
56
	       index=0;
57
	       metacatURL="$metacatBaseURL$suffix"
58
	    fi
59
	fi		
60
done
61

    
62
#This will send out some remained docid
63
if [ $index -ne 0 ]
64
then   
65
    echo "here is url $metacatURL"
66
    wget -q -O - --load-cookies cookies "$metacatURL"
67
fi
68

    
69
exec 0<&3
70
date
71
exit 0
(2-2/3)