cc: [email protected]
Subject: Re: [ast-users] how to control function execution on background
--------
> Hello Forum
>
> I would like your advise on how to manage below logic.
> I have to collect crontabs from list of servers.
> Most are running well.
> For some of them, ssh execution hangs forever.
> What I would like to do is to start function ssh_ on background and if it
> does n
> ot create expected file or still on afteer 15 sec, I want to kill it and go
> forw
> ard.
> Codding looks like:
>
> function ssh_
> {
> rm -f ssh_end_flag
> ssh user1 host1 <<! > host1.out
> crontab -l
> !
> touch ssh_end_flag
> }
>
> #MAIN
> while read USER HOST
> do
> ssh_ USER HOST
> #... some logic
> done < host.file
>
> My idea is to call ssh_ on background.
> Meanwhile I should check if ssh_ is still on for later then 15 sec. or if
> it's d
> one already and file output have size > 0.
>
> I don't know how to identify as a process and kill ssh_ execution function.
> Please help.
>
> Thank you,
>
>
>
> Gene
>
Why don't you write the following function
pid=
function timeout # sec pid
{
sleep $1
[[ $pid ]] && kill -9 $2
}
and then do
ssh_ & pid=$!
timeout 15 $!
wait $!
pid=
David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users