The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Running app after logout and monitoring ncatdesigner High Level Programming 1 04-21-2008 05:39 AM
Monitoring Processes - Killing hung processes ukndoit UNIX for Advanced & Expert Users 4 01-17-2008 04:30 AM
Monitoring processes of another host Andimotz80 Shell Programming and Scripting 5 07-10-2006 08:43 PM
getting certain info for all processes currently running Yifan_Guo High Level Programming 3 03-25-2005 07:53 PM
Running two processes in background jacob_gs Shell Programming and Scripting 6 05-13-2002 11:40 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-21-2007
nhatch nhatch is offline
Registered User
  
 

Join Date: Aug 2002
Location: London, England
Posts: 84
monitoring running processes

I have a script that runs continuously and will deliver a file to multiple servers via scp. On occasions one of the scp's will hang and as a result not complete in sending the remaining files and not loop around again.

If I run the scp commands with a & they'll complete, but I want to make sure the sends have finished before looping again.

My question is how do I monitor the 6 PID's and kill any that have run for more than 2 minutes?

I was going to capture the PID into an array and then use that some how.

Just can't work out the best way.

Any ideas?

They'll be some Christmas cheers for the winner
  #2 (permalink)  
Old 12-21-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,507
post your code
  #3 (permalink)  
Old 12-21-2007
andryk's Avatar
andryk andryk is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2003
Posts: 448
Quote:
Originally Posted by nhatch View Post
I have a script that runs continuously and will deliver a file to multiple servers via scp. On occasions one of the scp's will hang and as a result not complete in sending the remaining files and not loop around again.

If I run the scp commands with a & they'll complete, but I want to make sure the sends have finished before looping again.

My question is how do I monitor the 6 PID's and kill any that have run for more than 2 minutes?

I was going to capture the PID into an array and then use that some how.

Just can't work out the best way.

Any ideas?

They'll be some Christmas cheers for the winner
Not really after Xmas cheers (not in the mood and will never be ) but here's an idea on how you might monitor and kill any that timed out
Code:
#!/bin/sh

TIMER=120
CMD=scp

mysleep()
{
   sleep $1
   CMDPID=`ps -ef |grep $$ |grep $CMD |grep -v grep |awk '{print $2}'`
   for i in $CMDPID
   do
         kill -9 $CMDPID
   done
}

while true
do
        echo Loop ...
        mysleep $TIMER &
        scp ... ... ...
done
Just put 'mysleep 120 &' before scp'ing, proceed with care, not tested

Last edited by andryk; 12-21-2007 at 09:09 AM..
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0