Linux - Networking This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
07-26-2001, 06:54 AM
|
#1
|
Member
Registered: Jul 2001
Location: Braunschweig, Germany
Distribution: Suse 7.2
Posts: 184
Rep:
|
Shutdown tool
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?
THANX!
|
|
|
07-26-2001, 10:42 PM
|
#2
|
Senior Member
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821
Rep:
|
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
|
|
|
07-27-2001, 04:19 PM
|
#3
|
Member
Registered: Jul 2001
Location: Braunschweig, Germany
Distribution: Suse 7.2
Posts: 184
Original Poster
Rep:
|
Switch...
Third editing:
First: THANX a lot!
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?
Last edited by Steave; 07-27-2001 at 06:03 PM.
|
|
|
07-27-2001, 10:30 PM
|
#4
|
Senior Member
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821
Rep:
|
When you try to run the script in a shell and you intend to log out execute the script with nohup.
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.
Gary
|
|
|
07-27-2001, 10:56 PM
|
#5
|
Member
Registered: Jul 2001
Location: Braunschweig, Germany
Distribution: Suse 7.2
Posts: 184
Original Poster
Rep:
|
HI!
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.
Thanx for ya help!
Last edited by Steave; 07-27-2001 at 10:58 PM.
|
|
|
07-28-2001, 12:58 AM
|
#6
|
Senior Member
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821
Rep:
|
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 can look at fixing up the script a bit later.
Gary
|
|
|
07-28-2001, 01:01 AM
|
#7
|
Senior Member
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821
Rep:
|
I forgot to add that if you do not have netwatch. You can get it from this site:
http://www.slctech.org/~mackay/netwatch.html
Gary
|
|
|
07-28-2001, 03:10 PM
|
#8
|
Member
Registered: Jul 2001
Location: Braunschweig, Germany
Distribution: Suse 7.2
Posts: 184
Original Poster
Rep:
|
I got myself netwatch and ran it...
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.
Which options should I set in the config-file??
|
|
|
07-28-2001, 07:48 PM
|
#9
|
Member
Registered: Jul 2001
Location: Braunschweig, Germany
Distribution: Suse 7.2
Posts: 184
Original Poster
Rep:
|
Jippiieee!
The script is finally running!! I had two typos in there.
Didn't know there is a difference between
TIME_STAMP = ... and
TIME_STAMP=...
probably also interesting for others.
and- as soon as the win2k-box has nobody logged in- there isn't any traffic on the network.
Its all working out great now. Thanx!
|
|
|
All times are GMT -5. The time now is 11:34 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|