Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
What I would love to have for my DSL-Router would be a tool that monitors network activities and shuts down my Suse 7.2 if there wasn't any activity on any network device (eth0,eth1) for -lets say- an hour to avoid excessive running time of the server -> save energy!!
Has anyone seen such a tool or can provide me with a script or binary?
Here is a simple shell script that will shut the box down after 1 hour of no ethernet activity on eth0 and eth1. Remember, even a ping at 59 minutes will keep the box alive another hour.
This script needs to be run as root to execute the poweroff.
Code:
#!/bin/sh
POWERDOWN_SECS=3600
LAST_ETH0=0
LAST_ETH1=0
TIME_STAMP=0
while [ 1 ]; do
VALUE_ETH0=`cat /proc/net/dev | grep eth0 | awk ' { print $2 } '`
VALUE_ETH1=`cat /proc/net/dev | grep eth1 | awk ' { print $2 } '`
if [ $LAST_ETH0 -eq $VALUE_ETH0 ]; then
if [ $LAST_ETH1 -eq $VALUE_ETH1 ]; then
if [ $TIME_STAMP -eq 0 ]; then
TIME_STAMP=`date +'%s'`
else
NEW_STAMP=`date +'%s'`
DIFF=`expr $NEW_STAMP - $TIME_STAMP`
if [ $DIFF -gt $POWERDOWN_SECS ]; then
/sbin/poweroff
fi
fi
else
TIME_STAMP=0
fi
else
TIME_STAMP=0
fi
LAST_ETH0=$VALUE_ETH0
LAST_ETH1=$VALUE_ETH1
sleep 20;
done
After trying around a bit, I got the script to run -finally
Two problems remain:
major:
Even with the script running, the PC won't shut down! I started it as root vi ssh and then logged out... The Computer is hooked up to a switch-- does this cause any traffic on the devices i.a. for checking bandwidth?
minor
after starting the script with
./shutdownscript &
and then typing logout my ssh client doesn't tell me that the foreign host closed the connection as it does normally... Probably the two problems are connected somehow.
still, if I login afterwards, the script is still running
And: What lines should I add to my startup scripts so that this script is executed on every boot?
When you try to run the script in a shell and you intend to log out execute the script with nohup.
Code:
nohup script.sh&
This will prevent the script from being killed by a hup signal by the shell. It appears that you do not have that problem though.
When I tested the script I had set the powerdown_secs set at 20 and the sleep set at 5. I had to go down into the basement to use the console to eliminate network traffic. Even at 20 seconds it took a couple loops of the script to have no network activity for 20 seconds and echo out the powerdown.
I'm guessing that one of your daemons is sending out packets, thus not causing the machine to powerdown. I'd suggest that you set the value a bit lower, like 60 seconds, and echo out the /sbin/poweroff line. Watch the script execute at the console and see if it writes out the line. If that fails, then you can write out a bit more debug. I can help you out with that if you are unfamiliar with shell scripting.
You can add the script to your network rc file anywhere after they are brought up. I don't know which distro you have and what type of rc scripts it has.
Since I'm pretty unfamiliar with shell scripting, I still need some help: could you do me a favour and for debugging purposes give me some script that logs network activity (time would be great) to a file to see if any deamon is sending packets??
There are quite a few of them running... -> Is the smb-protocol always sending packets??
Does the line
echo /sbin/powerdown | file
log the powerdown-calls to the specified file??
What I want off the script is that my router should power down if no win2k/me client is using it as router, proxy and/or fileserver.
I think that samba may be pushing packets out to see if its shares are still alive.
If you have netwatch installed, try running it on the console for about an hour when you expect no network traffic. It will log every bit of traffic in and out of the machine. This will let you know if there is any odd traffic.
The line:
Code:
echo /sbin/powerdown > /tmp/filename
will echo out "/sbin/powerdown" to a file called filename in the tmp directory. You were using a pipe, which would cause the file named 'file' to be executed and the contents '/sbin/powerdown' passed as standard input.
I just donn't know how to read the logs or how I have to configure the conf-file so all network activity is logged. I used the script provided at the home page. It did put some log files in my home-directory, but they seem to be empty although I definitely caused some traffic. (ssh, smb, ...) just to test.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.