LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-14-2011, 04:35 AM   #1
Jyothi.yis
LQ Newbie
 
Registered: May 2010
Posts: 12

Rep: Reputation: 1
Script for automatic shutdown


hi,

I need a script for shutdown the system automatically if the system is not disturbed for last 10 minutes.

Please have a look and help in these regards. By the way i am using RHEL 4 in my system.
 
Old 01-14-2011, 05:28 AM   #2
puntjuh
Member
 
Registered: Apr 2006
Location: holland
Distribution: Gentoo / debian / suse / mint
Posts: 558

Rep: Reputation: 42
A simple google search leads me to the following script which should work for you. If you change the threshold (amount of minutes) to 10, and change the userid for the user you want to check for inactivity, this script should serve your purpose.

Code:
#!/bin/bash
#
# This is scheduled in CRON using ROOT, it runs every 5 minutes
# and uses who -a to determine user activity. Once the idle time is
# more than the threshold value it shuts the system down.
#
echo "Start of sidle.shl"

threshold=25
log=/home/ubuntu/sidle.log
userid=kids
inactive=`who -a | grep $userid | cut -c 45-46 | sed 's/ //g'`

if [ "$inactive" != "" ]; then

echo "Idle time is: " $inactive

if [ "$inactive" -gt "$threshold" ]; then
echo "Threshold met so issuing shutdown command"
/sbin/shutdown -h now
else
echo "Bellow threshold"
fi
else
echo "Idle time is: 0"
fi

echo "Ending"
 
Old 01-14-2011, 05:31 AM   #3
smart_shell
Member
 
Registered: May 2009
Location: NYC
Distribution: Ubuntu 10.04 LTS
Posts: 52

Rep: Reputation: 0
Code:
#!/bin/bash
#
# This is scheduled in CRON using ROOT, it runs every 5 minutes 
# and uses who -a to determine user activity. Once the idle time is
# more than the threshold value it shuts the system down.
#
echo "Start of sidle.shl"

threshold=25
log=/home/ubuntu/sidle.log
userid=kids
inactive=`who -a | grep $userid | cut -c 45-46 | sed 's/ //g'`

if [ "$inactive" != "" ]; then

echo "Idle time is: " $inactive

if [ "$inactive" -gt "$threshold" ]; then
echo "Threshold met so issuing shutdown command"
/sbin/shutdown -h now
else
echo "Bellow threshold"
fi
else
echo "Idle time is: 0"
fi 

echo "Ending"
http://ubuntuforums.org/showpost.php...05&postcount=5

Last edited by smart_shell; 01-14-2011 at 05:33 AM. Reason: double :)
 
Old 02-27-2013, 01:52 AM   #4
Jyothi.yis
LQ Newbie
 
Registered: May 2010
Posts: 12

Original Poster
Rep: Reputation: 1
what is threshold

hi,

thanks for the script. It is working fine. But my requirement to shutdown the linux machine if it inactive for 15min. could you kindly help me regarding this.
 
Old 02-27-2013, 01:58 AM   #5
devUnix
Member
 
Registered: Oct 2010
Location: Bengaluru, India
Distribution: RHEL 5.1 on My PC, & SunOS / Sun Solaris, RHEL, SuSe, Debian, FreeBSD and other Linux flavors @ Work
Posts: 576

Rep: Reputation: 48
You can modify the line:

Code:
threshold=25
 
Old 02-27-2013, 10:01 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,932

Rep: Reputation: 3691Reputation: 3691Reputation: 3691Reputation: 3691Reputation: 3691Reputation: 3691Reputation: 3691Reputation: 3691Reputation: 3691Reputation: 3691Reputation: 3691
Quote:
Originally Posted by Jyothi.yis View Post
hi,
I need a script for shutdown the system automatically if the system is not disturbed for last 10 minutes. Please have a look and help in these regards. By the way i am using RHEL 4 in my system.
RHEL4 is old, and should be updated. And have you looked in the Red Hat knowledgebase, since you're paying for access to it?

And if you need a script, then post what you've written so far and tell us where you're stuck...we'll be happy to HELP you, but this isn't the place to come to have folks write scripts for you. Also, the question itself is vague...what do you mean by "not disturbed"? Do you mean no mouse movements on the GUI console? No new user logins? What?? If you mean that you want to know if users that are already logged in haven't done anything, that's next to impossible. A user could be running a bash shell, which is always running...and they could just go home and leave it there. They could also run a script in the background which spawns a new shell...which means the original has zero activity, but the user is still doing something. Explain what you mean in detail, and post what you've written.
Quote:
Originally Posted by puntjuh
A simple google search leads me to the following script which should work for you. If you change the threshold (amount of minutes) to 10, and change the userid for the user you want to check for inactivity, this script should serve your purpose.
Nope, it doesn't.

If you look at the script, it's looking for ONE user ID only.

Last edited by TB0ne; 02-27-2013 at 10:11 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Overheating Automatic Shutdown? Super TWiT Linux - Hardware 2 07-01-2010 02:04 PM
can I time an automatic shutdown? newbiesforever Linux - General 10 01-04-2009 11:24 AM
automatic shutdown muhammednavas Fedora 1 12-01-2006 11:48 AM
Automatic system shutdown chobin SUSE / openSUSE 2 06-05-2006 09:51 AM
Automatic shutdown NetScripter Linux - General 1 10-17-2002 03:45 PM


All times are GMT -5. The time now is 01:17 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration