Menu

sample-probe-run-script

consulare

Sample Probe Run Script

This is a sample probe run script. The pid is managed to avoid parallel runs and the output is redirected in a temporary file that is then send.

 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
#!/bin/bash
JAVA_HOME=/usr/java/current; export JAVA_HOME
PGDATA=/opt/my_app/pgdata; export PGDATA
HOME=/opt/esis-framework/trunk
PID=/opt/my_app/var/run/my_app_fetch.pid
NOW=`date +%s`
OUTPUT=/tmp/my_app_fetch_out_$NOW
silent=1

while [ "$1" != "" ]; do
    case $1 in
        -v | --verbose )         shift
                                silent=0
                                ;;
        * )                     exit 1
    esac
    shift
done

if [ -f $PID ]; then
        pid=`cat $PID`
    if [ "$silent" = "0" ]; then
            echo "Found PID file for pid $pid."
            echo "Checking $pid is an existing PID."
    fi
        nbf=` ps -p $pid | wc -l`
        if [ $nbf -eq 1 ]; then
        if [ "$silent" = "0" ]; then
                    echo "PID $pid do not match any running process"
        fi
                rm -f $PID
        fi
fi

# Avoids a second launch
if [ -f $PID ]; then
    if [ "$silent" = "0" ]; then
            echo "A fetch is already running with PID $PID."
            echo "You should wait for it to complete."
    fi
        exit 1;
else
        echo $$ > $PID
fi

(cd $HOME 
touch $OUTPUT
. ./env.sh >> $OUTPUT 2>&1
scripts/cmd probes xml app/my_app/data/sample-probes.xml >> $OUTPUT 2>&1
end=`date +%s`
diff=`expr $end - $NOW`
echo "Started at $NOW : Ended at $end" >> $OUTPUT 2>&1
echo "Elapsed time = $diff seconds" >> $OUTPUT 2>&1
# email output
scripts/cmd emails email_text support@example.com probes $OUTPUT
rm $OUTPUT)

rm $PID

Related

Wiki: Home
Wiki: Probe-Run

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.