LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-26-2001, 05:54 AM   #1
Steave
Member
 
Registered: Jul 2001
Location: Braunschweig, Germany
Distribution: Suse 7.2
Posts: 184

Rep: Reputation: 30
Question 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!
 
Old 07-26-2001, 09:42 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
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
 
Old 07-27-2001, 03:19 PM   #3
Steave
Member
 
Registered: Jul 2001
Location: Braunschweig, Germany
Distribution: Suse 7.2
Posts: 184

Original Poster
Rep: Reputation: 30
Smile 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 05:03 PM.
 
Old 07-27-2001, 09:30 PM   #4
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
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.

Gary
 
Old 07-27-2001, 09:56 PM   #5
Steave
Member
 
Registered: Jul 2001
Location: Braunschweig, Germany
Distribution: Suse 7.2
Posts: 184

Original Poster
Rep: Reputation: 30
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 09:58 PM.
 
Old 07-27-2001, 11:58 PM   #6
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
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
 
Old 07-28-2001, 12:01 AM   #7
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
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
 
Old 07-28-2001, 02:10 PM   #8
Steave
Member
 
Registered: Jul 2001
Location: Braunschweig, Germany
Distribution: Suse 7.2
Posts: 184

Original Poster
Rep: Reputation: 30
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??
 
Old 07-28-2001, 06:48 PM   #9
Steave
Member
 
Registered: Jul 2001
Location: Braunschweig, Germany
Distribution: Suse 7.2
Posts: 184

Original Poster
Rep: Reputation: 30
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!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help on how to save services shutdown or shutdown from the terminal. wambuzz Linux - General 2 03-11-2005 07:38 AM
Linux full shutdown vs. manual shutdown? LQtoto Linux - General 9 01-26-2005 06:21 PM
unable to 'shutdown' from x... need to shutdown using 'halt' guitarnix Linux - Newbie 5 11-24-2003 01:00 AM
konsole shutdown possible? or key combo = shutdown possible? Laptop2250 Linux - Newbie 3 11-16-2003 10:44 AM
URLSCAN tool MS = Linux tool ? OB1 Linux - Security 3 10-05-2002 12:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 08:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration