Author Topic: Power management run script not working [solved]  (Read 562 times)

Offline janasx1

  • Full Member
  • ***
  • Posts: 147
Power management run script not working [solved]
« on: November 19, 2012, 08:56:37 PM »
Hi,
I added a script to execute when my laptop hits low battery condition. But it does not look like its executing.
Here is how/what I did.

open "System settings"
go to Hardware > Power Management > Energy Saving > On Low Battery
Checked the check box next to "Run Script" gave the path to the script. The script has execute and read permissions to all users.
Select After option and 1 min (also tried On Profile Load)

The script has following lines.

echo `date` executing $0 >> ~/vm-suspend.log
for vm in `VBoxManage list runningvms | cut -d " " -f 2`; do echo saving $vm; VBoxManage controlvm $vm savestate; done


Thanks
« Last Edit: November 28, 2012, 10:19:25 PM by janasx1 »
HP Pavilion notebook DV6400, AMD Turion TL-64, 2GB RAM, broadcom BCM4312, nvidia Geforce Go 6150

Offline janasx1

  • Full Member
  • ***
  • Posts: 147
Re: Power management run script not working
« Reply #1 on: November 21, 2012, 10:28:59 PM »
Has anyone tried the run script option in power management?
Thanks
HP Pavilion notebook DV6400, AMD Turion TL-64, 2GB RAM, broadcom BCM4312, nvidia Geforce Go 6150

Offline muungwana

  • Hero Member
  • *****
  • Posts: 6245
Re: Power management run script not working
« Reply #2 on: November 21, 2012, 10:37:17 PM »


echo `date` executing $0 >> ~/vm-suspend.log
for vm in `VBoxManage list runningvms | cut -d " " -f 2`; do echo saving $vm; VBoxManage controlvm $vm savestate; done



I think the highlighted line is problematic.It is a mistake for a script running in a back ground to attempt to write to stdout or stderror because a script running in a background runs without being connected to any terminal.

remove the line or redirect its output to a file and try again.

just to be safe,you should always explicitly redirect outputs of scripts and programs they start if they are to run as a service in a back ground.
.. 3 things are certain in life : death, taxes and software bloat ..
.. tell me something i don't know, something i can use as i struggle to reason with the world around me ..

Offline janasx1

  • Full Member
  • ***
  • Posts: 147
Re: Power management run script not working
« Reply #3 on: November 27, 2012, 09:43:49 AM »
Thanks muungwana.

I commented out the entire line and still dont see it getting executed.

Here is the new script...


$ cat saveRunningVBoxes.sh
echo `date` executing $0 $* >> /home/janakiramans/vm-suspend.log
#for vm in `VBoxManage list runningvms | cut -d " " -f 2`; do echo saving $vm; VBoxManage controlvm $vm savestate; done


I also tried under Hardware>Power Management>Advanced Settings>Configure Notifications>Low Battery>Run Command

Is there any log for the power management?
Thanks
HP Pavilion notebook DV6400, AMD Turion TL-64, 2GB RAM, broadcom BCM4312, nvidia Geforce Go 6150

Offline daniel

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3739
  • God knows, i'm not an Angel!
    • Tipps und Tricks
Re: Power management run script not working
« Reply #4 on: November 27, 2012, 10:21:34 AM »
Can you post the full script?

Offline janasx1

  • Full Member
  • ***
  • Posts: 147
Re: Power management run script not working
« Reply #5 on: November 27, 2012, 06:35:25 PM »
The script has only 2 lines and the second one is commented.
The first line is just an echo to a log file.

echo `date` executing $0 $* >> /home/janakiramans/vm-suspend.log
#for vm in `VBoxManage list runningvms | cut -d " " -f 2`; do echo saving $vm; VBoxManage controlvm $vm savestate; done
HP Pavilion notebook DV6400, AMD Turion TL-64, 2GB RAM, broadcom BCM4312, nvidia Geforce Go 6150

Offline daniel

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3739
  • God knows, i'm not an Angel!
    • Tipps und Tricks
Re: Power management run script not working
« Reply #6 on: November 28, 2012, 02:53:49 AM »
The script has only 2 lines and the second one is commented.
The first line is just an echo to a log file.

echo `date` executing $0 $* >> /home/janakiramans/vm-suspend.log
#for vm in `VBoxManage list runningvms | cut -d " " -f 2`; do echo saving $vm; VBoxManage controlvm $vm savestate; done


and why is the second commented?
That will not work...

A script should read as
Code: [Select]
#!/bin/bash
#
# some statements, what it do, from who, and license, maybe website from Author
# and who has it generated
#
echo `date` executing $0 $* >> /home/janakiramans/vm-suspend.log
for vm in `VBoxManage list runningvms | cut -d " " -f 2`; do echo saving $vm; VBoxManage controlvm $vm savestate; done

and it should executable, to get it running.

If you start it from terminal, (i don't know how it could) as

Code: [Select]
./script

What the messages from terminal?

Offline janasx1

  • Full Member
  • ***
  • Posts: 147
Re: Power management run script not working
« Reply #7 on: November 28, 2012, 10:06:40 PM »
Thanks Daniel.

I commented out the second line to confirm the comment from muungwana.

At this point, I am also thinking of keeping just the first echo statement so that we know the script is getting executed and then enable the second line so that we will be narrow down if there is any issue in the second line.

When I execute the script in command line, it just exits normally and adds the echo output to the log file.
Here is a sample from manual execution of the script...

Thu Nov 29 00:01:45 EST 2012 executing ./saveRunningVBoxes.sh
HP Pavilion notebook DV6400, AMD Turion TL-64, 2GB RAM, broadcom BCM4312, nvidia Geforce Go 6150

Offline janasx1

  • Full Member
  • ***
  • Posts: 147
Re: Power management run script not working
« Reply #8 on: November 28, 2012, 10:18:45 PM »
Now my script is...


Code: [Select]
#!/bin/bash
#

echo `date` executing $0 $* >> /home/janakiramans/vm-suspend.log
#for vm in `VBoxManage list runningvms | cut -d " " -f 2`; do echo saving $vm; VBoxManage controlvm $vm savestate; done

Now the script is getting executed and the echo message comes to the log file when the laptop goes to low battery.

Thanks for the help!!!
HP Pavilion notebook DV6400, AMD Turion TL-64, 2GB RAM, broadcom BCM4312, nvidia Geforce Go 6150

Offline janasx1

  • Full Member
  • ***
  • Posts: 147
Re: Power management run script not working [solved]
« Reply #9 on: November 28, 2012, 10:53:02 PM »
Now I enhanced the script little bit for more logging.

Code: [Select]
#!/bin/bash
#

echo `date` executing $0 $* >> /home/janakiramans/vm-suspend.log
for vm in `VBoxManage list runningvms | cut -d " " -f 2`; do echo saving $vm >> /home/janakiramans/vm-suspend.log; VBoxManage controlvm $vm savestate;echo saved $vm >> /home/janakiramans/vm-suspend.log; done
echo `date` executed $0 $* >> /home/janakiramans/vm-suspend.log

Additional background info...

This script gets the list of running virtual box virtual machines and saves the current state (similar to hibernate).
Without this script, if the laptop hits hibernate because of critical battery, the machine hangs (looks like it) because of running virtual box.
With this script, the running virtual boxes will be saved when the laptop hits low battery and will hibernate the host os (PCLOS here) at critical battery.

Thanks
HP Pavilion notebook DV6400, AMD Turion TL-64, 2GB RAM, broadcom BCM4312, nvidia Geforce Go 6150