Run script when computer resume from being sleep state


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run script when computer resume from being sleep state
# 1  
Old 09-14-2018
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?

Code:
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

# 2  
Old 09-15-2018
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
# 3  
Old 09-15-2018
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... )
# 4  
Old 09-15-2018
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.
Code:
#!/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.
# 5  
Old 09-15-2018
Well this is totally untested pseudo-code but might be useful:
Code:
# 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.

This User Gave Thanks to wisecracker For This Post:
# 6  
Old 09-15-2018
Thanks.

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

Code:
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?

Last edited by drew77; 09-16-2018 at 11:10 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

How to run a Windows Setup on a Linux computer?

I am looking to run a Windows utility BitRecover PST Viewer. To help me read a pst file. Can anybody guide me how can I run this Windows utility on Linux. (3 Replies)
Discussion started by: marktux
3 Replies

2. UNIX for Advanced & Expert Users

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (6 Replies)
Discussion started by: naveeng
6 Replies

3. UNIX for Advanced & Expert Users

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (1 Reply)
Discussion started by: naveeng
1 Replies

4. BSD

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (0 Replies)
Discussion started by: naveeng
0 Replies

5. Hardware

Cannot resume from suspend with new motherboardktop, does not resume properly

I would like to get pm-suspend (or any other suspend method) working for a small new desktop computer. It is based on a Zotac GF-8200 ITX motherboard and an AMD Athlon II X@ 240 CPU using ArchLinux x86_64. The pm-suspend script works, apparently putting the machine into suspend correctly... (0 Replies)
Discussion started by: lagagnon
0 Replies

6. Shell Programming and Scripting

How to run a process when the computer is idle?

Hi there, I wrote a script that scans a folder for new files. I don't want to run it at specific times but only when the computer is NOT busy. I tried to use nice but it doesn't really work. I mean, even if my process has less priority, it still slows down the other processes. I did a test... (3 Replies)
Discussion started by: chebarbudo
3 Replies

7. Shell Programming and Scripting

Perl Script to resume download

Hi, i am looking for a perl script that can resume broken download images from a remote server. Can anyone help me on this. thanks, Vince (1 Reply)
Discussion started by: vin_eme
1 Replies

8. What is on Your Mind?

Are companies viewing my resume? How do I track my resume visits?

Hi everybody, I am wondering if there is any tool or website out there which can track who is viewing my resume. It is very frustrating when you send your CV or Cover Letter and you receive no feedback from the company, you don't even know if they have checked it out. Thanks for your help (1 Reply)
Discussion started by: gearyipswich
1 Replies

9. UNIX for Dummies Questions & Answers

how can I run something as root (modprobe, to be exact) every time computer starts.

I have the root password for my box, but I'm ignorant. So, every time I start my computer, I have to run this command /sbin/modprobe fuse as su, so that I can do other stuff (like mount remote directories locally using sshfs) I guess there's some file, like .bashrc, only it's applicable... (4 Replies)
Discussion started by: tphyahoo
4 Replies

10. UNIX for Dummies Questions & Answers

How to run a script when your computer is idle

I am trying to run a script that I made when my computer is idle. How do I go about doing this. Thanks :) (4 Replies)
Discussion started by: rehansaeed
4 Replies
Login or Register to Ask a Question