source: trunk/projects/ForwardCronJob/publish @ 7725

Revision 7725, 2.8 KB checked in by ealexand, 9 years ago (diff)

These are the files used in the cron job that creates thumbnails of images collected by WiscScan and copies them to the Forward directory on open.microscopy.wisc.edu. In order to run, CreateThumbnail.java must be compiled with loci_tools.jar in the classpath and the log4j.properties file. Paths in the "publish" script are relative to the open.microscopy.wisc.edu machine.

Line 
1#!/bin/bash
2# This cron job is used to upload METS files and thumbnails to Forward.
3# Written by Eric Alexander.
4
5FORWARD_PATH='/var/www/forward/adds'
6DATA_PATH='/data'
7
8METS_FILES=`find $DATA_PATH -name '*.xml'`
9SYM_LINKS=`find $FORWARD_PATH -name '*.xml'`
10TIFF_FILES=`find $DATA_PATH -name '*.ome.tiff'`
11
12#echo "TIFF_FILES: "$TIFF_FILES
13#echo "METS_FILES: "$METS_FILES
14#echo "SYM_LINKS: "$SYM_LINKS
15
16for mets_file in $METS_FILES
17do
18    new=true
19    #echo "CURRENT METS_FILE " $mets_file
20   
21    # If file is already in directory, ignore it.
22    for sym_link in $SYM_LINKS
23    do
24        cmp -s $mets_file $sym_link
25        if [ $? -eq 0 ]
26        then
27            new=false
28            break
29        fi
30    done
31 
32    # Else, create a symlink to it.
33    if $new
34    then
35        # Get the base filename.
36        i=0
37        lastslash=-1
38        while [ $i -lt ${#mets_file} ]
39        do
40            if [ "${mets_file:$i:1}" = "/" ]
41            then
42                lastslash=$i
43            fi
44            i=$((i+1))
45        done
46        basename=${mets_file:$((lastslash+1))}
47        basename=${basename:0:$((${#basename}-4))}
48
49        # Make sure a matching tiff exists.
50        match=false
51        for temp_tiff in $TIFF_FILES
52        do
53            extractedXML=`tiffcomment $temp_tiff`
54            if [[ $extractedXML == *urn:lsid:loci.wisc.edu:Dataset:$basename\"* ]]
55            then
56                tiff_file=$temp_tiff
57                match=true
58                #echo "MATCH" $tiff_file
59                break
60            fi
61        done
62        if ! $match
63        then
64            echo "Error: No tiff file matches" $basename
65            echo "Skipping to next METS file."
66            continue
67        fi
68
69        # Make sure no file exists of same name.
70        # e.g. If 'test.xml' already exists, link as 'test_1.xml'.
71        if [ -e $FORWARD_PATH/$basename.xml ]
72        then
73            i=1
74            basename2=''
75            while [ true ]
76            do
77                basename2=$basename'_'$i
78                if [ ! -e $FORWARD_PATH/$basename2.xml ]
79                then
80                    break
81                fi
82                i=$((i+1))
83            done
84            basename=$basename2
85        fi
86
87        # Generate a thumbnail
88        # Usage: javac -cp loci_tools.jar:. CreateThumbnail originalPath newThumbnailPath
89        #echo "About to javac"
90        #echo "tiff_file: "$tiff_file
91        #echo "newThumbnailPath: "$FORWARD_PATH/$basename.tiff
92        java -cp loci_tools.jar:. CreateThumbnail \
93            $tiff_file $FORWARD_PATH/$basename.jpg > /dev/null
94
95        # If everything went smoothly, symlink the metadata
96        if [ $? -eq 0 ]
97        then
98            ln -s $mets_file $FORWARD_PATH/$basename.xml
99        fi
100    fi
101done
102
103# Curtis' Notes:
104#
105# 1. symlink metadata (into /var/www/forward) from hits that are new
106# 2. generate a thumbnail in /var/www/forward using Bio-Formats
107#    put loci_tools.jar in /opt/forward
108#    put .java file there too, compile to .class file:
109#      "javac -cp loci_tools.jar MyProgram.java"
110#    call "java -cp loci_tools.jar:. MyProgram arguments"
111
112# Once this script works well, it will be symlinked into /etc/cron.hourly
113# Also needs to have 755 permission set
114
115# I recommend the Bash Advanced Scripting Guide... google it
116
117# Cron jobs should output nothing unless there is a problem
Note: See TracBrowser for help on using the repository browser.