Hi everyone,
It's a pleasure for me to join your community.
I am still a "freshman" in Linux and in bash scripting, but I am glad to say that with a bit of help I managed to complete my first script. But much more important is the fact that I am getting increasingly enthusiastic and hooked to this great OS and the many unique possibilities that scripting presents...
And here is the final product of many hours of hard work
Code:
#!/bin/bash
echo
echo "This script will find all the open ports on a computer."
echo "It will also show the process that has opened each one and the number of files opened per process."
echo
echo
showProcesses()
{
lsof -i | uniq -f 7 > table.list
cat table.list | awk 'NR>1{print "Process name\t"$1"\t\t\ton port\t\t"$8}'
}
showNumberOfFiles()
{
cat table.list | awk 'NR>1{print $2}' > PID.list
while read pid; do
lsof -p $pid | wc -l | awk '{print "\t\t\tNumber of files opened\t"$1}'
done < PID.list
}
showProcesses > file1.list
showNumberOfFiles > file2.list
paste file1.list file2.list
echo
It's a fairly simple one and what I want to do with it now is to format it like a table. I used the paste command and some tabs to try and allign the data so that it is legible but coudldn't do it. Does anyone have an idea how I can accomplish this?
Kindest regards,
Valentin