LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 03: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, 04: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, 04: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 04:33 AM. Reason: double :)
 
Old 02-27-2013, 12: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, 12:58 AM   #5
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Rep: Reputation: 59
You can modify the line:

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

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
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 09:11 AM.
 
  


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:16 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