Hi,
On Sun, Jul 12, 2009 at 11:56, Matthias Meyer<matthias.meyer AT gmx DOT li>
wrote:
> As an alternative you can place the following script in /etc/crontab.
> #!/bin/bash
> declare -a hosts
> hosts[0]=server1 # fill in your own host names
> hosts[1]=server2 # whose backup should be canceld
> hosts[2]=server3
> declare -i hostcount=3 # configure your count of killable hosts
>
> ps ax | grep "BackupPC_dump -i" | grep -v grep > /tmp/runnings
> while read pid fl1 fl2 duration perl dump fl3 host rest
> do
> for (( a=0; a<hostcount; a++ ))
> do
> if [ $host == ${hosts[a]} ]; then kill -9 $pid > /dev/null
> 2>&1; fi
> done
> done < /tmp/runnings
> exit 0
Not only "kill -9" should not be used in normal circumstances (as
already pointed out by Chris), as the script could be simplified:
hosts="server1 server2 server3" # list of servers in a string
ps ax | grep "BackupPC_dump -i" | grep -v grep | while read pid fl1
fl2 duration perl dump fl3 host rest; do
for i in $hosts; do
if [ x"$host" = x"$i" ]; then
kill "$pid" >/dev/null 2>&1
break
fi
done
done
1) Use a list of hosts and iterate with "for i in $hosts" instead of
using C style iteration with number of elements in an array.
2) No need to use a temporary file, use |while on the output of ps instead.
3) Use "kill" instead of "kill -9"
4) Once a host is found, use "break" so that it does not iterate to
the end of the list of hosts.
You can even create a script file in which you remove the first hosts=
line and replace "for i in $hosts; do" with "for i; do", in which case
you can call it like this:
# ./killbackups.sh server1 server2 server3
HTH,
Filipe
------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
BackupPC-users mailing list
BackupPC-users AT lists.sourceforge DOT net
List: https://lists.sourceforge.net/lists/listinfo/backuppc-users
Wiki: http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/
|