shell seconds every state record netstat

Explanation

Similar operations may be random Trojan heartbeat packets are sent, the random sleep. In such cases written a shell script monitor, every second on the next record netstat state.

Code

#!/bin/bash
#功能:用于定时执行lsof 和 netstat 的执行状态并记录到文件

slptime=1   #默认一秒执行一次
filedir=/tmp        #默认存储在/tmp下
lsoffile=lsof.log   #存储lsof的执行结果
netstatfile=netstatfile.log #存储netstat执行结果



while true

do
    sleep $slptime
    date=$(date '+%Y-%m-%d %H:%M:%S')
    
    echo $date":" >> $filedir/$lsoffile
    echo $date":" >> $filedir/$netstatfile
    lsof -i   >> $filedir/$lsoffile
    netstat -tunlp >> $filedir/$netstatfile

done

Guess you like

Origin www.cnblogs.com/17bdw/p/11495108.html