Operating System - HP-UX
1828481 Members
3125 Online
109978 Solutions
New Discussion

Trying to do netstat with count option

 
SOLVED
Go to solution
joe wong_2
Advisor

Trying to do netstat with count option

I'm trying to gather net statistics daily and put them in a file with the date as its name. I created a crontab entry to start netstat every night at midnight with an interval of 5 minutes but I have to terminate the previous night's job manually everyday because there is no count field allowed on the netstat command. Any suggestions will be much appreciated!
3 REPLIES 3
Michael Steele_2
Honored Contributor

Re: Trying to do netstat with count option

Have a 2nd cron go off in the morning that grep's for 'netstat'. Then kill using the PID.

0 6 * * * ps -ef | grep -i netstat | while read a b c
do
kill $b
done
Support Fatherhood - Stop Family Law
curt larson_1
Honored Contributor
Solution

Re: Trying to do netstat with count option

sort of the same thing

#run netstat in the backgroud
(netstat command)&

secsPerMin=60
minPerHour=60
hours=4

# sleep for the length netstat is to run
sleep $(($hours * $minPerHour * $secsPerMin))

# kill netstat/background job
kill $!

joe wong_2
Advisor

Re: Trying to do netstat with count option

Thanks Michael and Kurt!

I've tried both suggestions and both worked really well. There is a little bit of side effect on Michael's suggestion though. The do-while will kill other people's netstat processes if there happens to be any.