Re: Standby for homeserver

MaxEigelb wrote:
> Hi,
>
> i would like my little homeserver (SUSE 11.0 - no X, Via Esther 1GHz)
> to switch to standby after 60 minutes of no network-traffic. How to
> implement that?
>
> thanks a lot,
>
> Max
>
>

A small script should do it.



#!/bin/bash
# The function reads a kernel counter and calculates a unique checksum.
# ethernet port to be adjusted to your situation
md5 () { cat /proc/net/dev | grep eth1 | md5sum | cut -d' ' -f1; }

MD5a=$(md5) # Initial checksum of ethernet traffic
for ((i=0;i<60;i++));do # try for 60 minutes
sleep 60
MD5b=$(md5) # A second readout after a minute.
if  "$MD5a" != "$MD5b" ]; # Anything changed?
then
exec sh -x $0 # Yes; restart script and counter
fi
done
# Nothing changed in the traffic count for one hour.
echo switching to standby
# Your code to switch to standby here


Editing my other self:
The ‘exec -x $0’ should read ‘exec $0’

I wonder though if you will ever attain that no-traffic condition because there are always broadcast packets flying around on a LAN, ARP packets, etc. Maybe only checksum the outgoing packet count?

ken yap wrote:
> I wonder though if you will ever attain that no-traffic condition
> because there are always broadcast packets flying around on a LAN, ARP
> packets, etc. Maybe only checksum the outgoing packet count?
>
>

You’re right, it’s probably never going to fall through to the standby,
mode while there is a cable attached to the ethernet interface.

If I were the OP, I would be more interested in connections to certain
services than random network traffic.