]> www.hackdaworld.org Git - outofuni/backup.git/blob - bin/backupctrl
just pick the date, no sed exp
[outofuni/backup.git] / bin / backupctrl
1 #!/bin/bash
2
3 op="pusage"
4
5 function detect() {
6         IFS=$'\n'
7         for psline in `ps -ef | grep [r]sync`; do
8                 ppid="`echo $psline | awk '{ print $2 }'`"
9                 pptime=`echo $psline | awk '{ print $5 }'`
10                 ppcmd="`echo $psline | \
11                         sed 's/.*\(rsync .*\)/\1/'`"
12                 echo
13                 echo posible backup process $ppid started at $pptime
14                 echo
15                 if [ ! -z "$1" ]; then
16                 if [ "$1" = "kill" ]; then
17                         echo -en "want me to kill it? [y/N]: "
18                         read answer
19                         echo
20                         if [ "$answer" = "y" ]; then
21                                 kill -9 $ppid
22                         fi
23                 fi
24                 fi
25         done
26         IFS=""
27 }
28
29 #if [ $# = 1 ]; then
30         case $1 in
31                 status)
32                         if [ ! -f ~/.backup ]; then
33                                 echo
34                                 echo "backup activated (no rejection file)"
35                                 detect
36                         else
37                                 txt="`grep ^# ~/.backup | cut -d ' ' -f 2-`"
38                                 if [ -z "`cat ~/.backup | grep ^off`" ]; then
39                                         echo
40                                         echo backup activated, $txt
41                                         detect
42                                 else
43                                         echo
44                                         echo backup rejected, $txt
45                                         detect "kill"
46                                 fi
47                         fi
48                         ;;
49                 off)
50                         echo "# disabled at `date`" > ~/.backup
51                         echo "off" >> ~/.backup
52                         detect "kill"
53                         ;;
54                 on)
55                         echo "# enabled at `date`" > ~/.backup
56                         echo "on" >> ~/.backup
57                         ;;
58                 *)
59                         echo -en "\nusage:\n$0 [status|off|on]\n\n"
60                         ;;
61         esac
62 #fi
63