Hi
I want to write a script for netflow service
because my service doesnt send any packet to netflow walker (server).
Although the service is started but it does not send any packet to server until i restart the service
I want to write a script in order to restart the service when no packets have been sent to the server.
What operating system are you using?
What shell are you using?
Can you manually restart the service? If so, what command(s) do you use to restart the service? What do you want the script to do that can't be done by putting the command(s) you use to restart the service in a file and executing that file?
my operating system is Fedora linux and interpreter is bash
yes of course i manually restart the service when it does not send packet.
i want to write a script that detect this service does not send packet and then restart automatically.
I repeat:
And, how do you determine that "the service" does not send a packet?
by tcpdump ,
tcpdump is a tool for capture network traffic packet . i run this command on my system
for example :
tcpdump -i eth0 -p udp and port 9996 -nn
and then i see no any packet send to the server on this port and so restart the service and then every thing is going to OK
I write this script and it does work
#!/bin/bash
while true
do
tcpdump -i ETH1 port 9996 > /home/log_netflow &
pid=$!
sleep 5
kill $pid
count=`cat /home/log_netflow | wc -l `
echo $count
if [ $count -gt 2 ] ; then
echo " system is working " >> /home/service_status
else
echo "system is down " >> /home/service_status
/etc/init.d/netflowd restart
fi
done
Looks good!
Only one little efficiency tip
count=`wc -l < /home/log_netflow`