Run script when computer resume from being sleep state

I use this as a startup program.

Is there a way that it could run when my computer returns from a sleep state?

Cpu_LogFile="/home/andy/bin/CPU_Fan_Info.txt" date +"%Y-%m-%d-%H:%M:%S" >> $Cpu_LogFile sensors -f | grep "temp4" >> $Cpu_LogFile sensors -f | grep "fan1" >>  $Cpu_LogFile

If you have it, take a look at pmset ; this is capable of temporarily overriding the normal scheduled settings and you could code for your requirements accordingly...

pmset - Wikipedia

Well you havent said what was your box nor which OS you are talking about...
computer to me could be anything, like many of us I have all sorts except a PC ( not true I have one somewhere but not at home... )

I have a desktop and use Ubuntu Mate 18.04.

------ Post updated at 01:29 PM ------

I read the info here.

pm-action - Suspend or Hibernate your computer

I have this in /etc/pm/sleep.d/, but it does not run when computer returns from a sleep state.

#!/bin/bash  case "$1" in suspend|hibernate)      ;; resume|thaw)     /bin/bash /home/andy/bin/CPU_FAN_INFO.sh     ;; esac 

I have a hard time understand much of what is on the manual page.

Well this is totally untested pseudo-code but might be useful:

# Shebang and startup code here...
# Followed by...
# _Maybe_ a 'while' loop for cyclic operation... 
pm-suspend
printf "Press ENTER to continue:- "
read -r junk
# Your code here...
# A means of quitting the 'while' loop, if used.
1 Like

Thanks.

This may not be elegant, but it works.
Feedback appreciated.

echo "Coming back from sleep mode." >> /home/andy/bin/CPU_Fan_Info.txt
echo fake | sudo -S pm-suspend
/bin/bash /home/andy/bin/CPU_FAN_INFO.sh

I read somewhere that it is not necessary to ever turn off computer, but to use suspend.

Not sure I am comfortable with that.

What happens if a power outage occurs when it is suspended?