Add scripts to create myops-getqueryview:
[myops.git] / web / collect / client / upload.sh
1 #!/bin/bash
2
3 #if [ -f /tmp/source/configuration ] ; then
4 #    source /tmp/source/configuration
5 #elif [ -f /etc/planetlab/plc_config ] ; then
6 #    source /etc/planetlab/plc_config
7 #else 
8 #       PLC_MONITOR_HOST=IPADDR
9 #fi
10 #if [[ -z "$PLC_MONITOR_HOST" || "$PLC_MONITOR_HOST" = "localhost.localdomain" ]] ; then
11 #    PLC_MONITOR_HOST=monitor.planet-lab.org
12 #fi
13 if [ -f /etc/planetlab/plc_config ]; then
14         source /etc/planetlab/plc_config
15 else
16         PLC_SLICE_PREFIX='pl'
17 fi
18
19 export MYOPS_SERVER=IPADDR
20
21 function upload_log ()
22 {
23     file=$1
24     path=$2
25     base=$( basename $file )
26     old=/tmp/${base}.old
27     new=/tmp/${base}.new
28     log=/tmp/${base}.log
29     if [ ! -f $file ] ; then
30         return
31     fi
32     if [ -f $new ] ; then
33         cp $new $old
34     else
35         touch $old
36     fi
37     cp $file $new
38     #comm -1 -3 $old $new > $log
39     cp $new $log
40     if [ $( stat -c %s $log ) -ne 0 ] ; then
41         curl --max-time 60 --silent http://${MYOPS_SERVER}/upload.php --form "log=@$log"
42         if [ $? -ne 0 ] ; then
43             # the upload has failed, so remove new file so no data is lost
44             rm -f /tmp/$( basename $file ).new
45         fi
46     fi
47 }
48
49 function upload_logs ()
50 {
51     upload_log $1 multiops
52 }
53
54 upload_logs /home/${PLC_SLICE_PREFIX}_myops/myops.log
55