#!/bin/sh loggerName=tcpdump.sh Open_Protocol_Start(){ logfile=/var/run/op.dump CFG=/home/tool/config/OpenPrtclCfg.json port=`grep '"port":' $CFG | awk '{print $2}' | sed 's/"//g' | sed 's/,//'` logger -s -t $loggerName "Start tcpdump Open Protocol <$port>" &> /var/run/op.log #tcpdump -i eth0 -p -n -A -q port 4545 > /var/log/op.dump & #tcpdump -i eth0 -p -n -A -q -l port $port | egrep "IP|001" > /var/log/op.dump & rm $logfile tcpdump -i tiwlan0 -s 0 port $port -w $logfile >> /var/run/op.log 2>&1 & exit 0 } XML_Start(){ logfile=/var/run/xml.dump CFG=/home/tool/config/vwXmlCfg.json portA=`grep '"myValue":' $CFG | awk '{print $2}' | sed 's/"//g' | sed 's/,//' | sed -n 12p` portB=`grep '"myValue":' $CFG | awk '{print $2}' | sed 's/"//g' | sed 's/,//' | sed -n 14p` logger -s -t $loggerName "Start tcpdump XML Protocol <$portA,$portB>" &> /var/run/op.log rm $logfile tcpdump -i tiwlan0 -s 0 port $portA or $portB -w $logfile >> /var/run/xml.log 2>&1 & exit 0 } IPM_Start(){ logfile=/var/run/ipm.dump CFG=/home/tool/config/ipm/ipmgateway-config.xml port=`grep 'IPMIPPort=' $CFG | awk '{print $3}' | sed 's/"//g' | sed 's/IPMIPPort=//'` logger -s -t $loggerName "Start tcpdump IPM Protocol " &> /var/run/op.log rm $logfile tcpdump -i tiwlan0 -s 0 port $port -w $logfile >> /var/run/ipm.log 2>&1 & exit 0 } case "$1" in op) Open_Protocol_Start ;; xml) XML_Start ;; ipm) IPM_Start ;; profinet) logger -s -t $loggerName "Profinet not supported" ;; stop) kill $(pidof tcpdump) logger -s -t $loggerName "Stop tcpdump" ;; status) if pidof tcpdump; then exit 0; else exit 1; fi ;; *) logger -s -t $loggerName "Invalid Command <$1>" ;; esac logger -s -t $loggerName "Exit 0" exit 0