I have a python script that I need to run after resuming system from suspend. I have created an executable in /etc/pm/sleep.d/
#!/bin/bash
case "$1" in
hibernate|suspend|thaw|resume)
sudo /data/fan/fanSpeedScript.sh
;;
esac
running sudo /data/fan/fanSpeedScript.sh
does it's job in interactive terminal but the script is not running after resuming.
Here is the fanSpeedScript.sh
#!/bin/sh
python /data/fan/fanSpeed /data/fan/quiet
And the fanSpeed
#!/usr/bin/env python
import os
import sys
EC_IO_FILE="/sys/kernel/debug/ec/ec0/io"
if not os.path.exists(EC_IO_FILE):
os.system("modprobe ec_sys write_support=1")
def ec_write(addr,value):
with open(EC_IO_FILE,"rb") as f:
f.seek(addr)
old_value=ord(f.read(1))
if (value != old_value):
print(" %3d => %3d" % (old_value, value))
with open(EC_IO_FILE,"wb") as f:
f.seek(addr)
f.write(bytearray([value]))
else:
print(" = %3d" % value)
for line in open(sys.argv[1]).readlines():
print(line.strip())
if line.startswith(">WEC "):
addr,value=line.split()[1:3]
ec_write(int(addr,0), int(value,0))
Any help is appreciated.
thaw|resume
part, no need forhibernate|suspend
. Does the script require GUI ? Can you post the script contents ? – Sergiy Kolodyazhnyy Mar 28 '17 at 17:15sudo
– steeldriver Mar 28 '17 at 18:03/usr/bin/python
instead of justpython
- don't assume that system /etc/pm scripts inherit a particular environment – steeldriver Mar 28 '17 at 18:52