Run shell script even in sleep mode?

0

I want to create a script that logs the battery level and CPU load on a laptop, however I still want to log the battery level whilst in sleep mode. Is there any way to do this in Linux?

OS: LM 18.04 LTS
DE: Xfce

Computer specs: 10-12 year old laptop, it's pretty bad but fine for casual use: Celeron 900 2.2GHz, integrated graphics, 1366x768 display, 120GiB SSD; the model is something like Compaq Presario CQ56.

EDIT: I have a working script for logging battery level already which is this command:

upower -i $(upower -e | grep 'BAT') | grep -E "percentage" | awk -F: '{ print $2 }' | tr -d ' %'

Jachdich

Posted 2019-05-08T13:00:50.203

Reputation: 135

Answers

1

"Sleep" is defined as ultra-low power usage: All subsystems get turned off and consume extremely little power but can be woken up quite quickly by an external event: lid open, power button, key press, WOL packet, BIOS.

From https://unix.stackexchange.com/questions/257048/run-at-command-when-computer-is-sleeping

This means that you cannot run a program while the computer is sleeping. You could wake it up every 5 or 6 minutes and log the battery, however, wakeup will deplete the battery faster.

user2531336

Posted 2019-05-08T13:00:50.203

Reputation: 183

0

On sleep mode a computer won't be processing information, alas it won't run your script. You can check this amazing answer by DavidPostill.

But you can log the battery just before going to sleep and then on wake up. For that you will need to add your script to .../systemd/system-sleep/ and check you sleep hooks to run it depending on you distro flavor.

dmb

Posted 2019-05-08T13:00:50.203

Reputation: 1 166