-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshow_process
More file actions
executable file
·53 lines (46 loc) · 1.17 KB
/
Copy pathshow_process
File metadata and controls
executable file
·53 lines (46 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh
#lsof -p $pids
temp_dir="/tmp"
function showps () {
show_net_process
}
show_net_process ()
{
local pid_file=$temp_dir/pid
netstat -vanp tcp | awk 'NR > 2 {print $9}' | sed 'H;1h;$!d;x;y/\n/,/' > $pid_file;
local pids=$(cat $pid_file)
ps -p $pids
rm $pid_file
}
show_tcp_process ()
{
local netstat_file=$temp_dir/netstat.log
netstat -vanp tcp > $netstat_file
n=0
local filename=$netstat_file
local net_ps_file=$temp_dir/netps.log
if test -f $net_ps_file
then
rm $net_ps_file
fi
while read line; do
# reading each line
local line_file=$temp_dir/oneline
echo "Line No.$n:"
if [ $n -gt 1 ]
then
echo "$line" | awk '{print $1, $4, $5, $6, $11, $12}'
echo "$line" | awk '{print $1, $4, $5, $6, $11, $12}' > $line_file
pid=$(awk '{print $5}' $line_file)
#pid=$(echo "$line" | awk '{print $9}')
#echo "pid: $pid"
ps -p $pid | awk '{if(NR>1) print $4}'
rm $line_file
else
echo $line
fi
n=$((n+1))
done < $filename
rm $netstat_file
}
show_tcp_process