WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: powering off a TCL computer  (Read 6611 times)

Offline cast-fish

  • Hero Member
  • *****
  • Posts: 1000
  • hi there
powering off a TCL computer
« on: December 10, 2014, 08:23:53 PM »
Hello,

do you know any code snippet for TCL that will make the laptop switch OFF
if there is no video movement or mouse/keys interaction.?

For example

1) If there is no movement on the screen or mouse/keys activity for over 5 mins
shut down or hibernate this laptop.  (what's the code snipper for that?)

2) Or just a hard command such as  "shut down or hibernate this laptop 3 hours from now"
what's the code snippet for that?

thanks

V

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11631
Re: powering off a TCL computer
« Reply #1 on: December 10, 2014, 10:28:52 PM »
Hi cast-fish
Quote
2) Or just a hard command such as  "shut down or hibernate this laptop 3 hours from now"
what's the code snippet for that?
How about:
Code: [Select]
#!/bin/sh
#Number of seconds to wait before power off
DELAY=10800

sleep $DELAY
sudo poweroff

Offline kalu

  • Newbie
  • *
  • Posts: 41
Re: powering off a TCL computer
« Reply #2 on: December 11, 2014, 12:41:21 PM »
From busybox's website, it seems that that their power, reboot and halt commands already have a '-d SEC  Delay interval' similar to the shutdown command used in other GNU/Linux systems... I've never tried it though, so I don't know..

There's also a $TMOUT built-in variable that I know of that's in bash which automatically logs the user out after a set period of inactivity from the current terminal. I don't know if something similar exists in ash. But it seems like you need something more for GUI...

Offline cast-fish

  • Hero Member
  • *****
  • Posts: 1000
  • hi there
Re: powering off a TCL computer
« Reply #3 on: December 12, 2014, 01:24:11 AM »
Hello there and thanks for you reply..

Well it seemed to me to be just a scase of "scheduling a task" to do shutdown.

The web contained all the info to use "crontab" task scheduler and which line
of text and command to use......TCL also had it's cron daemon running....but
all of this still didn't work.

Something must have been wrong with my pointing the cron task to the "s2ram"
program. TCL and Cron certainly recognised that i was trying to do something but it
didnt work.

...in theory "crontab" is extremely simple to use so it's a bit
dissheartening to not get that working...


will have a try with your reply....and thanks

V
« Last Edit: December 12, 2014, 01:27:46 AM by cast-fish »

Offline cast-fish

  • Hero Member
  • *****
  • Posts: 1000
  • hi there
Re: powering off a TCL computer
« Reply #4 on: December 12, 2014, 01:51:31 AM »
Rich,

many thanks to you indeed.

Your shell script for shutdown is working. It is really simple isn't it.

thanks

V


Offline cast-fish

  • Hero Member
  • *****
  • Posts: 1000
  • hi there
Re: powering off a TCL computer
« Reply #5 on: December 17, 2014, 04:54:27 AM »
Hello,

Been continuing to look at what i imagined would be a readily available
and simple Linux command to "shutdown on idle" a Linux box.

Idle meaning no real screen activity or user interaction.

There are lots of web pages, but i am yet to see a global simple
command to do this....such as Bash or busybox or real simple shell script.

"5 mins has passed, there's nothing happening on this Linux box, shut it down, or hibernate it"

V
« Last Edit: December 17, 2014, 04:57:10 AM by cast-fish »

Offline core-user

  • Full Member
  • ***
  • Posts: 192
  • Linux since 1999
Re: powering off a TCL computer
« Reply #6 on: December 17, 2014, 07:19:57 AM »
Try taking a look at ACPI, (I think that might be what you are looking for).
http://www.acpi.info/

Edit: Also may apply - http://www.uefi.org/specsandtesttools
« Last Edit: December 17, 2014, 07:24:58 AM by core-user »
AMD, ARM, & Intel.

Offline netnomad

  • Hero Member
  • *****
  • Posts: 1026
Re: powering off a TCL computer
« Reply #7 on: December 17, 2014, 07:53:44 AM »
hi friends,

i use following command-line in my ~/.xsession or ~/.xinitrc

xautolock -detectsleep -time 8 -locker "/usr/local/bin/dorm" &

/usr/local/bin/dorm
#!/bin/sh
sleep 1
vt='/usr/bin/fgconsole'
### i had to remove my sound-modules before the suspend-to-ram
sudo rmmod oss_ich
sudo rmmod oss_usb
sudo rmmod oss_hdaudio
sudo rmmod osscore
sudo s2ram --force --vbe_save
/usr/bin/chvt $vt
sleep 1
### and to reload the sound-modules after the suspend-to-ram
sudo modprobe osscore
sudo modprobe oss_hdaudio
sudo modprobe oss_usb
sudo modprobe oss_ich

as an alternative you could choose "sudo shutdown -h now" under normal conditions, but with busybox you probably need something like "sudo poweroff", instead of my suspend-to-ram-script.
it worked flawless until 4.7.7, but later suspend-to-ram was broken for my configuration and my hardware-setup :(
« Last Edit: December 17, 2014, 08:05:53 AM by netnomad »

Offline cast-fish

  • Hero Member
  • *****
  • Posts: 1000
  • hi there
Re: powering off a TCL computer
« Reply #8 on: December 20, 2014, 02:50:26 AM »
hello,,,

can you help me with trying to POWER DOWN or suspend an idle Linux box.
(idle meaning no real GUI activity mouse or keys)

I have found a command that is able to watch an "already started process" for a WHILE
......and then suspend the computer if the process stops....

so my idea is to use the existing tinycore screensaver....to then trigger a suspend...

THerfore my questions are......

1).what is the name of the "already running screensaver daemon"?....or what's its regular PID?....is it the same PID each time?

2) alternatively...is there some new "process" which is started when the screensaver kicks in? and what's the name of it...... or is there some process which is stopped like Xvesa?.... do either have a name or regular same PID?

with this info above i could somehow tailor that command to then "suspend" the computer
when the screensaver kicks in...

i set the screensaver to 3 mins usually

xset s 180

here is the info below...

------------------------------------------------------------------------------------------------------------------------------------

If you want to monitor an already started process, you can do this in a shell :

# while pgrep &>/dev/null -f process_name; do sleep 60; done; sudo s2ram -f


process_name is where you fill it in....



thanks

V









« Last Edit: December 20, 2014, 02:56:11 AM by cast-fish »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: powering off a TCL computer
« Reply #9 on: December 20, 2014, 05:31:20 AM »
No, the X server's screen saver does not spawn or close any process, nor can it send an event for you to wait for, it has no code for that. Try netnomad's solution.
The only barriers that can stop you are the ones you create yourself.

Offline cast-fish

  • Hero Member
  • *****
  • Posts: 1000
  • hi there
Re: powering off a TCL computer
« Reply #10 on: December 20, 2014, 09:33:04 AM »
Curaga,

what is the timing amount on netnomads code?

when does it actually suspend?

also HOW is that code starting off?....automatically at boot?...

i am unsure how to do that....

V
« Last Edit: December 20, 2014, 09:43:23 AM by cast-fish »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11631
Re: powering off a TCL computer
« Reply #11 on: December 20, 2014, 01:12:50 PM »
Hi cast-fish
Here is a script that will check the status of the monitor every 30 seconds. Within 30 seconds of the monitor going blank the computer
will execute the  shutdown  command.
Create a file called  AutoOff.sh
Code: [Select]
#!/bin/sh
# Check if screen is off every DELAY seconds
DELAY=30

# Loop until the screen is off
while `xset -q | grep -q "Monitor is On"`
do
sleep $DELAY
done

# Shut down the computer
sudo poweroff
If you place it in  /home/tc/.local/bin/  it will be part of your backup and added to the path.
Create a file in  /home/tc/.X.d  containing
Code: [Select]
AutoOff.sh &This will automatically start the script once the desktop appears.

Offline cast-fish

  • Hero Member
  • *****
  • Posts: 1000
  • hi there
Re: powering off a TCL computer
« Reply #12 on: December 21, 2014, 04:25:51 AM »
Hello,

Rich, uh....this script does not work.

Having correctly followed your initial instructions and made the script file..... the last step involved creating a file at the location you stated...the file is called....AutoOff.sh.....and has the contents "AutoOff.sh &" minus qoutes.

All permissions were changed on the created files.....so they could be used.

On a virgin fresh TCL 4.3.1 boot..... from CD with a persistant TCE...
the computer just seems to boot to the desktop and immediately power off. No screensavers are ever
considered..... or a 30 second wait.

it is xvesa here

when looking at "xset -q" command....there does not seem to be any arguments like "monitor is on" or flags of that nature for the properties of x.

also Rich....all of the same stuff above was tried on  a fresh frugal HDD install of tcl 4.3.1(with persistent tce)....same results as above apply...

did you test this stuff

V

« Last Edit: December 21, 2014, 04:35:56 AM by cast-fish »

Offline cast-fish

  • Hero Member
  • *****
  • Posts: 1000
  • hi there
Re: powering off a TCL computer
« Reply #13 on: December 21, 2014, 05:55:21 AM »
managed to get an idle linux box to "suspend" by using similar answer to Netnomad above.

$ xautolock -time 5 -locker  /mnt/sda5/./shutdown

if the above command is entered...it seems to watch the Linux computer and
as soon as there is no keys or mouse or GUI activity it shuts down the machine
5 mins later...by pointing to Rich's shutdown script


interestingly, on a RAW boot of TCL 4.3.1 from CD.....the "xautolock" extension does not work.

However, on this 4.3.1 HDD system here...many other apps are installed ......and "xautoclock" must
be finding the missing dep that it needs....

so the repo must be wrong on 4.3.1

thanks a lot....saves energy here.

V
« Last Edit: December 21, 2014, 06:06:52 AM by cast-fish »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11631
Re: powering off a TCL computer
« Reply #14 on: December 21, 2014, 01:54:49 PM »
Hi cast-fish
Quote
did you test this stuff
Yes I did. When I run  xset -q  I get:
Code: [Select]
tc@box:~$ xset -q
Keyboard Control:
  auto repeat:  on    key click percent:  0    LED mask:  00000002
  XKB indicators:
    00: Caps Lock:   off    01: Num Lock:    on     02: Scroll Lock: off
    03: Shift Lock:  off    04: Group 2:     off    05: Mouse Keys:  off
  auto repeat delay:  660    repeat rate:  25
  auto repeating keys:  00ffffffdffffbbf
                        fadfffdfffdfe5ef
                        ffffffffffffffff
                        ffffffffffffffff
  bell percent:  50    bell pitch:  400    bell duration:  100
Pointer Control:
  acceleration:  2/1    threshold:  4
Screen Saver:
  prefer blanking:  yes    allow exposures:  yes
  timeout:  600    cycle:  600
Colors:
  default colormap:  0x20    BlackPixel:  0    WhitePixel:  16777215
Font Path:
  /usr/local/lib/X11/fonts/misc/,/usr/local/lib/X11/fonts/TTF/,/usr/local/lib/X11/fonts/Type1/,/usr/local/lib/X11/fonts/75dpi/,built-ins
DPMS (Energy Star):
  Standby: 600    Suspend: 600    Off: 600
  DPMS is Enabled
  Monitor is On
tc@box:~$
Maybe it's because I'm running Xorg and not Xvesa.