first script. need help and advice.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting first script. need help and advice.
# 8  
Old 10-06-2006
Thanks. I am currently working on a slightly different version but I am not sure that it will function properly so I would appreciate your help. I will post my code when I'm done.

Greetings
# 9  
Old 10-06-2006
This is the script I have and I think it is fairly simple since I was able to come up with it on my own. It would have been perfect but unfortunately the last part with the showNumberOfFiles shows an error message instead of the number of files. It says that no PID has been specified.
I am confused because I am using the same method for obtaining the data in both functions.
Can anyone tell me how I can fix this?

Code:
#!/bin/bash

showProcesses()
{
	netstat -tuv | awk '{print $4}' > portslist.list
	lsof -i < portslist.list | awk '{print $1}'
}

showNumberOfFiles()
{
	lsof -i < portslist.list | awk '{print $2}' > fileslist.list
	lsof -p < fileslist.list | awk '{print $1}' > numberoffiles.list
	wc -l < numberoffiles.list
}

echo The following are the open ports on your computer:
netstat -tuv | awk '{print $4}'

echo These are the processes on each port:
showProcesses

echo This shows the number of files:
showNumberOfFiles


Last edited by sanchopansa; 10-06-2006 at 09:08 AM..
# 10  
Old 10-06-2006
Could you post the contents of netstat -tuv or fileslist.list
# 11  
Old 10-06-2006
netstat -tuv
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 margarita.bg.nc:38486 jynx.bg.ncSmilieop3 TIME_WAIT
tcp 0 0 margarita.bg.nc:38175 cub.bg.nc:jabber-client ESTABLISHED
tcp 0 0 margarita.bg.nc:38218 tiger.bg.nc:3389 ESTABLISHED
tcp 0 0 margarita.bg.nc:32768 hal.bg.nc:netbios-ssn ESTABLISHED
# 12  
Old 10-06-2006
And the result of this
Code:
lsof -i < portslist.list | awk '{print $2}'

is

PID
56
87
606
608
5583

so I assume this must be the content of fileslist.list
# 13  
Old 10-06-2006
Quote:
It says that no PID has been specified.
as per lsof man page

Quote:
-p s This option selects the listing of files for the processes
whose ID numbers are in the comma-separated set s - e.g.,
‘‘123'' or ‘‘123,456''. (There should be no spaces in the
set.)

Multiple process ID numbers are joined in a single ORed set
before participating in AND option selection.
-p requires "," separated pid list(ie in 1 line). Your file fileslist.list provides them in multiple lines. Either you change all the pids in multiple lines to pid in 1 line separated by comma or use a loop to call lsof -p separately for each pid.

eg

while read pid; do
lsof -p $pid
done < fileslist.list
# 14  
Old 10-06-2006
Thanks you for your help, vish_indian.
I tried your suggestion but it shows an error message because the first line of the column says "PID" and then it doesn't go on the chech the others. Is there a simple way to start from the second line, or to cut the PID even before placing it into the file. This is my code for the function now:

Code:
showNumberOfFiles()
{
	lsof -i < portslist.list | awk '{print $2}' > fileslist.list
	while read pid; do
	lsof -p $pid | awk '{print $1}' > numberofiles.list
	done < fileslist.list
	wc -l < numberoffiles.list
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Advice on a backup script, maybe one is out there already?

Hi, Not sure whether this is the right place to post it. I decided to post it here 'coz Advanced and Expert users will most likely have the answer to what I am looking for. I want to backup scripts that I have access to to a tar file file and zip it. At the moment I am creating a directory... (4 Replies)
Discussion started by: newbie_01
4 Replies

2. Shell Programming and Scripting

Script advice

All I have 2 parent directories - input and output. Each parent has multiple sub-directories...each sub-directory has multiple files. Each parent directory structure is a mirror image of itself I need to poll the imput directory and if a new file is found, encrypt the file, move the file to... (2 Replies)
Discussion started by: davidra
2 Replies

3. Shell Programming and Scripting

Need advice on approach for script

Greetings all. I have a repository server which receives, without exhaggeration, several million files a week. The majority of these files are in .csv format, which means they're highly compressable. They are spread throughout numerous directories where there are configured monitoring utilities... (4 Replies)
Discussion started by: msarro
4 Replies

4. Shell Programming and Scripting

Advice on script

Hi folks, I use following script:- #!/bin/sh # cd Linbread TODAY=`date +"%m%d"` DATA=`grep $TODAY linbread.dat` HOUR=`date +"%H"` if then TOD="Morning" elif then TOD="Afternoon" else TOD="Evening" fi echo $DATA | gawk -F"|" '{printf("%s\n\n%s",$2,$3)}' > $$tmp fold -s -w60... (0 Replies)
Discussion started by: satimis
0 Replies

5. Shell Programming and Scripting

Looking for optimization advice on a short script

I already have a solution to my problem, but I'm looking to see if it can be made more succinct and faster. The problem: given a list, as shown below, extract the pathname for any file in a directory named 'ample' and return it's index into the list. The index is also in the data itself. Note that... (1 Reply)
Discussion started by: prigo
1 Replies

6. Shell Programming and Scripting

advice on shell script

Hello, I have this script running on cron every 20 minutes. By 12pm daily, our system is expecting all input files to be uploaded by the script. After this cutoff time, the script would still be running though, but i need some kind of alerts/logs to know which input files weren't received for... (1 Reply)
Discussion started by: gholdbhurg
1 Replies

7. Shell Programming and Scripting

Script Help/Advice

Alright, I feel like I have a pretty good basic knowledge of shell scripting, but this one is throwing me for a loop. I know I've seen something similar done with awk, but I couldn't find it with the search function. I've grepped through my log file and get results like this: --... (14 Replies)
Discussion started by: earnstaf
14 Replies

8. Shell Programming and Scripting

Script Advice please?

Ok. I want to parse a log file and search only for denied traffic for the previous hour. The log looks like this: Jun 18 17:47:56 routername 36806: Jun 18 17:53:01.088: %SEC-6-IPACCESSLOG: list ingress-filter denied tcp 1.2.3.4(1234) -> 6.7.8.9(53), 4 packets I only really care about the... (12 Replies)
Discussion started by: earnstaf
12 Replies

9. Shell Programming and Scripting

Advice on Script

I would like some advice on how to logically put together a script to handle a daily task of data gathering for the following problem. I have two files, file1 has 125,000 records that I cut and remove unwanted fields through scripts and cron. In file2, I have 25000 records that has the same... (4 Replies)
Discussion started by: greengrass
4 Replies

10. Shell Programming and Scripting

c-shell script advice please.

Hi, I have the following script running in my cron. -------------------------------------------------------------------- #!/bin/csh bnstat -p GPD_VSLinux | grep pg | grep varcon | awk '{print $1, $2, $3, $4, $5, $6, $7, $8, $9, $10}' > /tmp/LX_xbatch.log bnstat -p GPD_VSLinux_test | grep pg... (2 Replies)
Discussion started by: killerserv
2 Replies
Login or Register to Ask a Question