|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
first script. need help and advice.
Hello everyone,
This is my first post here and this is the first time I am using UNIX OS (Slackware). I find it really useful and powerful and would like to master it but as you may guess I am expreicing quite a few problems. I've been reading a few documentations about it and bash this week and now I am trying to make my first script (related to a task I got at the office) but I am really stuck. What I want it to do is make a list of all the open ports on the computer + the processes that have opened them + the number of files opened by each process. I tried using netstat with some of its options for the first two but it wouldn't work and for the last part I'm clueless. I would be really grateful if anyone could help me. Kindest regards |
| Sponsored Links | ||
|
|
|
|||
|
Quote:
It does lists the port numbers, but they get converted to service names from /etc/services. Try this: lsof -i -P Please check the man page for options that would be suitable for you. |
|
|||
|
Thanks very much, vish_indian.
I looked through the man page after you posted your first reply but I couldn't find what I needed. You were right that it lists the ports and now everything is fine with this. What I am confused now with is that I want for everyone of the processes that are listed with lsof -i -P to make a list of all the files that each one is using. I looked at the reference and it's done with lsof -p PID, but is there a way to incorporate these two commands into one so that it lists the processes and the files without having to manually run the lsof -p command for each process separately. |
|
|||
|
I realized that the lsof -i -P does not list all the open ports and therefore I now use Code:
netstat -tuv instead. In order to find the process at each port I use Code:
lsof -i:port number which displays the process and the PID and now with Code:
lsof -p PID > filelist.list; wc -l filelist.list; I display the number of files for each process. My problem is that in order to put this into a script I need to have access to the port numbers and PIDs. Is there a way of putting them into an array? Thanks for your help. |
|
|||
|
A very crude script
Quote:
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| linux |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| need advice | naner9 | UNIX for Dummies Questions & Answers | 1 | 11-01-2007 11:05 AM |
| Script Help/Advice | earnstaf | Shell Programming and Scripting | 14 | 10-11-2007 06:53 PM |
| Script Advice please? | earnstaf | Shell Programming and Scripting | 12 | 06-18-2007 05:55 PM |
| Advice on Script | greengrass | Shell Programming and Scripting | 4 | 02-11-2007 12:49 AM |
| c-shell script advice please. | killerserv | Shell Programming and Scripting | 2 | 06-20-2004 03:51 AM |