Solved

Kill the ftp process !

Posted on 1997-12-01
11
1,217 Views
Last Modified: 2013-12-26
I want to have a sh shell script to kill all the ftp process which have run for more than 2 hrs. I can find out those ftp process by using ps -ef | grep ^ftp
Also, I am not a super user, so I need a way to test it
0
Comment
Question by:clo1
11 Comments
 
LVL 2

Expert Comment

by:df020797
ID: 1295716
There is no way in shell scripts checking the run time of a process, only idle time.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1295717
#!/bin/csh
set p = `ps | grep ftp`
echo run time of process is $p[3]

0
 
LVL 2

Expert Comment

by:df020797
ID: 1295718
Thats the idletime, not runtime,
set p=`ps -ef| grep sched`
echo $p[3]
-> 0

Now... I dont think shed has run for 0 time units ;-) Its a BIT to important for the system. The machines uptime is months. Yes, I used a Sys V, Solaris, but it wouldnt do any difference if I use ps -ef on a BSDish ps... still is the idle time in $p[3] cuz I tried this with /usr/ucb/ps.

set p=`/usr/ucb/ps -ef`
echo $p[3]
-> 0.00

So my answer is still... runtime cant be accessed through ps ina  shell.

0
 
LVL 84

Expert Comment

by:ozo
ID: 1295719
#!/bin/sh
P=`ps | grep ftp`
T=`echo $P | cut -f3 -d' ' -`
echo run time of process is $T

0
 
LVL 2

Expert Comment

by:df020797
ID: 1295720
This I yield to... on a Sys V, not BSD. Cuz then it shows accumulated CPU time. So I back up.

(it didnt work with BSDish ps, but with Sys V ps).
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 84

Expert Comment

by:ozo
ID: 1295721
I didn't say -ef, since I thought that might be more system dependent,
but on my system  
set p=`/usr/ucb/ps -ef`
echo $p[3]
is PPID
$p[7] or $p[8] would be run time,
(depending on how many fields STIME took)

0
 
LVL 2

Expert Comment

by:df020797
ID: 1295722
Yapp... hence this discussion as coming to a "prestige" level, I took time to read the man files ;-)

I was though certain runtime wasnt in a ps listing, cause normally only ideltime is of interest. Then I suddenly knew where I got that erroneous idea from... w.

So, you deserve the points :-)
Hope clo1 realizes that.

Thanks for an interesting discussion, it sure lightened up my afternoon.
0
 
LVL 2

Author Comment

by:clo1
ID: 1295723
All I want is just check the time, if it is more than two hrs, so I need to kill this process.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1295724
If you really want to check run time, and not elapsed time or idle time, you might do something like:
#!/bin/sh
F=`ps -ef | grep ftp`
while test -n "$P"
do
T=`echo $P | cut -f3 -d' ' -`
if test $T -gt 120
then
PID=`echo $P | cut -f1 -d' ' -`
kill $PID
fi
P=`echo $P |  cut -f 5- -d' '`
done

0
 
LVL 1

Expert Comment

by:dhughes111797
ID: 1295725
On Solaris, Column 5 of ps output is STIME - starting time
of the process. (If you have another OS, your mileage may vary,
but it should be documented in the man page). You can
compare the STIME to the current time. If it's more than 2 hours,
you can kill it.
How to test? start a bunch of ftps to a remote site. Let them
sit there. run your script. It'll kill them because the processes are yours
0
 

Accepted Solution

by:
mikal120797 earned 50 total points
ID: 1295726
I am not sure there is a neat way to do this. It would probably be easier to write a simple program which returns the wall time of the named process. You could then use this program's output to work out which processes to kill.

The program would be placed in a for loop, would be handed each process id, and then you would look at the individual answers returned.

In fact, you don't even have to write the code for this program, Stevens includes it in Advanced Programming in the UNIX environment... The source code for this book is available at: ftp.uu.net in published/books/stevens.advprog.tar.Z the program is in section 8.15.

Is this any help?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 85
Best tools for Backup and restore of Wordpress site 6 55
lucky13 challenge 11 124
haveThree challenge 22 114
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now