[CentOS] Timeout for a script
amos.shapira at gmail.com
Thu Nov 13 02:51:36 UTC 2008
Or maybe the next script that cron executes can kill the previous one
as a first step before doing anything else.
On 11/13/08, Filipe Brandenburger <filbranden at gmail.com> wrote:
> On Wed, Nov 12, 2008 at 08:39, Jussi Hirvi <greenspot at greenspot.fi> 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
> 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:
>> (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
> /usr/bin/rsync -avzu --delete /root /home/palvelimet/bckserver1 &
> 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.
> CentOS mailing list
> CentOS at centos.org
Sent from Google Mail for mobile | mobile.google.com
More information about the CentOS