Sponsored Content
Full Discussion: monitoring running processes
Top Forums Shell Programming and Scripting monitoring running processes Post 302152782 by andryk on Friday 21st of December 2007 08:03:15 AM
Old 12-21-2007
Quote:
Originally Posted by nhatch
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 Smilie
Not really after Xmas cheers (not in the mood and will never be Smilie) 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 Smilie

Last edited by andryk; 12-21-2007 at 09:09 AM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Monitoring processes of another host

Does anyone have a script, which monitors the processes of another host? (5 Replies)
Discussion started by: Andimotz80
5 Replies

2. UNIX for Advanced & Expert Users

Monitoring Processes - Killing hung processes

Is there a way to monitor certain processes and if they hang too long to kill them, but certain scripts which are expected to take a long time to let them go? Thank you Richard (4 Replies)
Discussion started by: ukndoit
4 Replies

3. UNIX for Dummies Questions & Answers

monitoring 'waiting' processes

Is it possible to monitor processes whether they are waiting or active? Basically I would like to know since which TIME the process has been running and the state. :confused: (3 Replies)
Discussion started by: jon80
3 Replies

4. Programming

Need C program for monitoring a processes that are running in different nodes

Hey, I am doing a high availability project. I need coding(socket programming using C) to monitor processes that are running in different nodes with in a network cluster.At last if u could give me a program in C to monitor the process(whether it is running or failed),it would be very... (2 Replies)
Discussion started by: vigneshinbox
2 Replies

5. Shell Programming and Scripting

Cron job for monitoring processes

I have to monitor several processes in my application . i get the listing of these processes using the command ps -ax i want to write a shell script that will monitor the processes and if a process goes missing then it will send an email to my gmail account. I want to run this... (6 Replies)
Discussion started by: asalman.qazi
6 Replies

6. UNIX for Advanced & Expert Users

Monitoring cpu usage of mysql processes/threads/queries without any tool

hi all, i want to monitor mysql processes/threads/queries with respect to cpu usage.how can i do it? show processlist is of no use as no information abt cpu usage is given. plz help (7 Replies)
Discussion started by: rohitmahambre
7 Replies

7. Shell Programming and Scripting

how to know the running processes.

Hi can anybody help me regarding this.. i want know the output of ps -ef with explanation. how can we know the running processess. this is the output of ps -elf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 19 T root 0 0 0 0 SY ... (1 Reply)
Discussion started by: rajesh_pola
1 Replies

8. Solaris

Running processes on GZ/LZ

Hi guys just a question is it normal to see running process on a non-global zone in the global zone... processes such as cron. (3 Replies)
Discussion started by: batas
3 Replies

9. Linux

Running processes

Hi guys is it normal to have 5-10 cron/syslog processes running... in my case i got 10 cron process running. (4 Replies)
Discussion started by: batas
4 Replies
SCP(1)							    BSD General Commands Manual 						    SCP(1)

NAME
scp -- secure copy (remote file copy program) SYNOPSIS
scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 ... [[user@]host2:]file2 DESCRIPTION
scp copies files between hosts on a network. It uses ssh(1) for data transfer, and uses the same authentication and provides the same secu- rity as ssh(1). Unlike rcp(1), scp will ask for passwords or passphrases if they are needed for authentication. File names may contain a user and host specification to indicate that the file is to be copied to/from that host. Local file names can be made explicit using absolute or relative pathnames to avoid scp treating file names containing ':' as host specifiers. Copies between two remote hosts are also permitted. The options are as follows: -1 Forces scp to use protocol 1. -2 Forces scp to use protocol 2. -4 Forces scp to use IPv4 addresses only. -6 Forces scp to use IPv6 addresses only. -B Selects batch mode (prevents asking for passwords or passphrases). -C Compression enable. Passes the -C flag to ssh(1) to enable compression. -c cipher Selects the cipher to use for encrypting the data transfer. This option is directly passed to ssh(1). -F ssh_config Specifies an alternative per-user configuration file for ssh. This option is directly passed to ssh(1). -i identity_file Selects the file from which the identity (private key) for public key authentication is read. This option is directly passed to ssh(1). -l limit Limits the used bandwidth, specified in Kbit/s. -o ssh_option Can be used to pass options to ssh in the format used in ssh_config(5). This is useful for specifying options for which there is no separate scp command-line flag. For full details of the options listed below, and their possible values, see ssh_config(5). AddressFamily BatchMode BindAddress ChallengeResponseAuthentication CheckHostIP Cipher Ciphers Compression CompressionLevel ConnectionAttempts ConnectTimeout ControlMaster ControlPath GlobalKnownHostsFile GSSAPIAuthentication GSSAPIDelegateCredentials HashKnownHosts Host HostbasedAuthentication HostKeyAlgorithms HostKeyAlias HostName IdentityFile IdentitiesOnly KbdInteractiveDevices LogLevel MACs NoHostAuthenticationForLocalhost NumberOfPasswordPrompts PasswordAuthentication PKCS11Provider Port PreferredAuthentications Protocol ProxyCommand PubkeyAuthentication RekeyLimit RhostsRSAAuthentication RSAAuthentication SendEnv ServerAliveInterval ServerAliveCountMax StrictHostKeyChecking TCPKeepAlive UsePrivilegedPort User UserKnownHostsFile VerifyHostKeyDNS -P port Specifies the port to connect to on the remote host. Note that this option is written with a capital 'P', because -p is already reserved for preserving the times and modes of the file in rcp(1). -p Preserves modification times, access times, and modes from the original file. -q Quiet mode: disables the progress meter as well as warning and diagnostic messages from ssh(1). -r Recursively copy entire directories. Note that scp follows symbolic links encountered in the tree traversal. -S program Name of program to use for the encrypted connection. The program must understand ssh(1) options. -v Verbose mode. Causes scp and ssh(1) to print debugging messages about their progress. This is helpful in debugging connection, authentication, and configuration problems. The scp utility exits 0 on success, and >0 if an error occurs. SEE ALSO
rcp(1), sftp(1), ssh(1), ssh-add(1), ssh-agent(1), ssh-keygen(1), ssh_config(5), sshd(8) HISTORY
scp is based on the rcp(1) program in BSD source code from the Regents of the University of California. AUTHORS
Timo Rinne <tri@iki.fi> Tatu Ylonen <ylo@cs.hut.fi> BSD
February 8, 2010 BSD
All times are GMT -4. The time now is 12:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy