Find the answer to your Linux question:
Results 1 to 8 of 8
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    [SOLVED] Is there any program that could automatically turn off a computer ?


    Hello !

    I'm wondering if there is any program that could turn off my computer after a chosen time. For example, I choose a time on the software and my computer will be switched off when I'm not here.
    Is it possible ?

    Thank you !

  2. #2
    Linux Guru bigtomrodney's Avatar
    Join Date
    Nov 2004
    Location
    Ireland
    Posts
    6,133
    You can shutdown your computer from the command line using shutdown. Using this in combination with cron you can set your PC to shutdown anytime you like.

  3. #3
    forum.guy
    Join Date
    May 2004
    Location
    arch linux
    Posts
    18,733
    Doing as Big Tom suggested, you can set it to shutdown in a certain number of minutes, or at a certain time of the day.

    You could also make a button for it using some such command if you wish to run the command from the GUI.
    oz

  4. $spacer_open
    $spacer_close
  5. #4
    Thank you for your answers !

    I think I'm going to use the first way (using the command line "shutdown")

  6. #5
    Quote Originally Posted by IroniK View Post
    Hello !

    I'm wondering if there is any program that could turn off my computer after a chosen time. For example, I choose a time on the software and my computer will be switched off when I'm not here.
    Is it possible ?

    Thank you !
    I wrote a script.
    Code:
    #!/bin/bash
    
    if [ "`whoami`" != "root" ];
    then
    	echo "You must be root to run this.";
    	exit 1;
    fi
    
    if [ $# -ne 1 ];
    then
    	echo "You didn't specify the time. e.g. 12:00";
    	exit 2;
    fi
    
    while true
    do
        CurrentDate=`date`
        CheckThis=`echo $CurrentDate | grep $1`
        
        if [ -n "$CheckThis" ];
        then
    	echo "Shutting down now: `date`.";
    	shutdown -h now;
        else
    	echo "Waiting some more: `date`";
    	sleep 1m;
        fi
    done
    It verifies the date from minute to minute. It's not the smartest design, someone smarter than myself would've calculated the difference between the current and target time then just have waited for it to run out. But anyway, this ought to work.

  7. #6
    Oh, thanks a lot for this.

  8. #7
    why all the scripting and cron and such?

    Code:
    $ shutdown -h +30
    will shutdown the system in 30 minutes, or

    Code:
    $shutdown -h 16:28
    will shutdown the system at 4:28PM, for more details:

    Code:
    $ man shutdown

  9. #8
    Quote Originally Posted by darkrose0510 View Post
    why all the scripting and cron and such?
    [...]

    Code:
    $shutdown -h 16:28
    That made me laugh out loud (at my own stupidity), I don't know what got into me when I wrote the script. Sorry. If nothing else, it may teach a bit of Bash syntax.

    Oh well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •