LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Log netstat at interval (https://www.linuxquestions.org/questions/linux-newbie-8/log-netstat-at-interval-497194/)

DaHoe 10-31-2006 08:10 AM

Log netstat at interval
 
Hi, I'm about to go crazy over this shell script thingy and crontab editing.

My final goal besides taking over the world and crown me to ultimate ruler of my brain, is to log a simple NETSTAT to a file at a 2 second interval between 6am - 6pm.

I'm no good at programming so all help is appreciated!

from commandline the netstat would look someting like:

netstat >> /home/guest/netstat.txt

how do i get it to run every 2 seconds in above mentioned time-span?

I've tried to write my own shell script. It wouldn't even work from commandline, and crontab wont go every 2 seconds so I'm stuck.

unSpawn 10-31-2006 08:40 AM

Not to thwart your in your quest for Ultimate Brain Domination, but why do you actually want to do this?
If we know the reasons we might be able to suggest faster, more efficient and exisiting (reinvent wheel) solutions.

DaHoe 11-01-2006 01:47 AM

uhm, well..

I got these 2 windows 2003 terminalservers and the AES 5.2 UNIX system.

When the guys at marketing uses the unix system wich they do all the time, they usually print to pdf via acrobat, when they log in to the unix system they have to tell wich port they want to request the acrobat trough. sometimes the acrobat port is used and they have to logout and then login with a different portnumber.
I have no lagal rights to alter the login to the UNIX server so I tought I could log the traffic and then maybe give the users a span of ports not used by the server.

thats why I need the netstat, or is there a really smart linux way of doing this? I've done the netstat on the two terminalservers just to check if it works.. results: on each TS there is a txt file @ 1.213GB :P

Got one of my co-workers fixxin a script to sort out the junk from the things I need.

unSpawn 11-01-2006 06:08 AM

So we're talking about Adobe Distiller, right? And it is the UNIX version? Does the box run SNMP by any chance? If so, then it's easy to set up a line for showing ports in use by distiller. If there's no SNMP then it's still rather easy. While netstat is one way to list all ports in use it's way too broad (can't really select). So if you can grab the process ID of distiller (for instance with "pgrep" but a ps|grep should do too) it's easier to feed that info into a more selective app like "lsof" (in the GNU/Linux dialect "lsof -i -a -p $PID -Fn" should do) and parse that output into a list of used ports. If the box runs a webserver it's easy to make that a CGI that refreshes when asked for, which is better for performance, but that's icing on the cake.

So the yes/no questions are: distiller? UNIX? SNMP? lsof? And what is the process name called?

DaHoe 11-06-2006 02:11 AM

No distiller found, yes, UNIX AIX 5.2, SNMP not foud either, no lsof either:/
process names, for each user instance: sh, todayx, crom.exe

apparently it also can export to exel and stuff, so not only pdf, tough when a user logs in to the unix system, it starts a couple of new processes, havent had the chans to test any pgrep yet.

I noticed in the config file each user has for the unix system, there is a row "crmrshdport=131177"
without a port number assigned the user cannot log in.
I think i only have to monitor the sh process for each user, right?


All times are GMT -5. The time now is 03:32 AM.