LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-09-2007, 12:38 AM   #1
ala_frosty
Newbie
 
Registered: Mar 2006
Posts: 8

Rep: Reputation: 0
Need to shutdown after LAN inactivity


Hi:

I'd like to set up a Linux box (CentOS) to shutdown after a period of LAN inactivity in the interest of saving some cash on electricity and some ice on carbon dioxide emissions. I've done a bunch of googling looking to see how to shutdown the computer. I think /sbin/halt will stop it, but I don't know how to set up something else to run the command at the appropriate time.

I can restart the computer remotely with Wake-on-LAN (WOL) but I need the piece to shut it down automatically. In the worst case scenario, I guess I could run a cron job every half an hour, but I'd still need to know what to look at.

Suggestions? Comments? Rants?

Thanks,

Ess
 
Old 02-09-2007, 07:03 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
shutdown after a period of LAN inactivity
I think you first need to define what counts as "inactivity":
- is there a period the box is less likely to be used (say working hours)?
- what services does the box run?
- do regular users only login remotely or locally as well?
- is it OK to still shut down if all, some or specific processes make use of the box?

If you for instance have only remote users you could use the amount of open network connections to determine a shutdown. Silly example:
Code:
#!/bin/sh --
# Unset debugging and exit-on-error after checking it works as advertised.
set -xe
# Get amount of connections.
CONN=`/bin/netstat -ntu 2>/dev/null| grep -c -v LIST 2>/dev/null`
# Check if var has contents, then scrub netstat headers (x2), else just exit.
if [ -n "$CONN" ]; then CONN=$[${CONN}-2]; else exit 1; fi
# If zero connections, initiate shutdown sequence with a 10 minute warning, else do nothing.
case "$CONN" in 0) /sbin/shutdown -h `date --date='+10 minutes' '+%H:%M'`;; 
*) ;; esac
exit 0
This cronjob is extendible with checks for which users are logged in, processes running and any other filter you can think of. Still YMMV(VM).
 
Old 02-10-2007, 11:13 AM   #3
ala_frosty
Newbie
 
Registered: Mar 2006
Posts: 8

Original Poster
Rep: Reputation: 0
I'm not terribly knowledgeable about all this, but it looks like if the cron job runs and there are no users at that time, the server will shut down. This approach examines a snapshot of the server's performance/duty.

What I was thinking of was more along the lines of an activity review. I don't have a lot of users on the network, so there may be periods of up to an hour, say, when there is no network activity, but someone might still wish to use it. It is acting as an internal file server and web server.

I suppose that to accomplish this, I would need to be able to look at a log of something(???) that would indicate the pages served by apache and the files served by samba, and user logins (if someone is logged in via SSH, I don't want to boot them). If there was no acitivity during the past hour, then the box could shut down. I think I'd set the script up to run every fifteen minutes.

Does anyone have any suggestions along these lines?

Thank you
 
  


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
Inactivity Timeout thisObject Linux - Software 3 07-27-2006 01:48 AM
TCP Inactivity Timer jonty_11 Linux - General 1 01-23-2005 11:23 PM
Wake on Lan - Link on b4 power up, No Link light after shutdown? Mark007 Linux - Networking 0 11-20-2004 08:16 PM
Server does'nt send mail until shutdown and LAN can't send or receive. Wolfy Linux - Networking 0 08-02-2004 07:31 PM
Inactivity setting bspicer Linux - General 1 05-17-2002 05:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:31 PM.

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