Re: Timeout for a script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Or maybe the next script that cron executes can kill the previous one
as a first step before doing anything else.

--Amos

On 11/13/08, Filipe Brandenburger <filbranden@xxxxxxxxx> wrote:
> Hi,
>
> On Wed, Nov 12, 2008 at 08:39, Jussi Hirvi <greenspot@xxxxxxxxxxxx> wrote:
>> Thanks - but I couldn't make that work as expected. It seems to kill
>> *something*, but after that, the rsync part still continues in the
>> background...
>
> If what you want to kill is the rsync process, do the opposite, run
> rsync in background, sleep for some time, test if it is still running
> and then kill it.
>
>> Here's my last test:
>>
>> log='/root/log/rsync2'
>> timeoutseconds=1
>> pid=$$
>> (sleep $timeoutseconds;
>>    echo `date '+%c'` " $0 INTERRUPTED" >>$log;
>>    kill -9 $pid) &
>> /usr/bin/rsync -avzu --delete /root /home/palvelimet/bckserver1
>> echo `date '+%c'` " $0 valmis" >>$log
>
> Use something like:
>
>
> #! /bin/bash
> timeout=60
> /usr/bin/rsync -avzu --delete /root /home/palvelimet/bckserver1 &
> rsync_pid=$?
> sleep "$timeout"
> # test if process $rsync_pid is still a child of this process:
> ppid_rsync=`ps -o ppid= "$rsync_pid"`
> # remove any spaces
> ppid_rsync=`echo $ppid_rsync`
> # compare the parent of $rsync_pid with this process, if it matches,
> kill $rsync_pid
> test x"$ppid_rsync" = x"$$" && kill "$rsync_pid"
>
>
> It's certainly more convoluted than it should be... but it should work.
>
> The C solution is probably the right thing to do, if you have time to
> dig into it and find out how it works.
>
> HTH,
> Filipe
> _______________________________________________
> CentOS mailing list
> CentOS@xxxxxxxxxx
> http://lists.centos.org/mailman/listinfo/centos
>

-- 
Sent from Google Mail for mobile | mobile.google.com
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux