clearer names for actions, and infer actions better
[monitor.git] / histlog / collect_log_sh
1 #!/bin/bash
2 function upload_log ()
3 {
4     file=$1
5     path=$2
6     old=/tmp/$( basename $file ).old
7     new=/tmp/$( basename $file ).new
8     log=/tmp/$( basename $file ).log
9     if [ -f $new ] ; then
10         cp $new $old
11     else
12         touch $old
13     fi
14     cp $file $new
15     comm -1 -3 $old $new > $log
16     if [ $( stat -c %s $log ) -ne 0 ] ; then
17         curl --insecure https://monitor.planet-lab.org/monitor/uploadlogs --form "dir=$path" --form "log=@$log"
18         if [ $? -ne 0 ] ; then
19             # the upload has failed, so remove new file so no data is lost
20             rm -f /tmp/$( basename $file ).new
21         fi
22     fi
23 }
24
25
26 upload_log ~/.bash_eternal_history hist
27 #upload_log /var/log/secure hist
28