Waking up from hibernate stopped watch script [LITE]

maybe I should bring this problem to stack forum, since this is more related to scripting. and post the solution here once i got it.

Yes, suspending your computer is stopping the script.
It will not Auto-resume itself because no part of it tells it to do so. It is not being stopped from resuming, because no part of the script tells it to resume in the first place.
Resuming your session does not automatically resume your script for you.

When you suspend the computer by closing the lid, this translates to you saying to the computer, “I would like to suspend the machine, if that is alright with you.”
If there are background processes running that it needs to finish, it will continue until finished without suspending. So let’s say you close the lid, it kills the Screen and Backlight, but continues to run until those processes are complete. This does not always happen, maybe about ten percent of the time or a bit more or a bit less… It happens when a process still running must finish before closing. This can last a few seconds, a few minutes or if there is a loop, can last several hours.

Once it suspends, then the script is stopped. It cannot resume without being told, either by you starting it or by you including a part in the script that tells itself to resume. I think you are thinking that if the script is to execute a command every second, then it should do so within 1 second. But it cannot do so at all unless the Script is Started.
The script can be started with a Resume function in the script, for example:

#!/bin/sh
case “$1” in
hibernate|suspend)
;;
thaw|resume)
vlock -ans
;;
*) exit $NA
;;
esac

And the script placed in your /lib/systemd/system-sleep/ folder
I pointed to the above documentation on your computer.
Stack is a good choice, too.

Other references that may help:

@Aravisian say bro, my question is crystal clear right? is there something wrong with my question?

  1. I run watch bash bash.sh
  2. I close laptop lip to suspend
  3. next day, I open laptop lid to wake up
  4. BOOM! 2 possibilities (50/50 chance):
    4a. the watch command continue running.
    4b. Why is it not running?

it this too hard to digest bro? what I dont like from stack community is that 90% of the population are nerd that has some disgusting hobby, dowvoting my question. I only found 1 or 2 salutable expert of all stack universe of all time.

Quenyan,

Please re-read each and every post I have made in this thread carefully.

It makes sense if you think about it… If a Script automatically started itself, then every script in every piece of software on your computer would start the moment you opened the lid or booted the computer.

Clearly, that is not how it works.

Before a command within a script can be issued, the Script Itself Must Be Started (or resumed).

I explained how this works three times above and this makes a forth time.

I explained once about how a program can be still running sometimes even after a suspend was placed on the machine and how sometimes it does not.

I have answered your question clearly and even provided some Script Material that you can use and I provided resources.

So… Let me make Myself Crystal Clear for you: When people like me take a lot of time, for free, to help people out without much in the way of thanks… You would be Wise To Speak to us Courteously.

@Aravisian Sorry if you felt like I’m mad at you, I am not. I’m just mad at Stack community, and I just sharing my thoughts here with you.

And, about your saying “Once it suspends, then the script is stopped. It cannot resume without being told, either by you starting it or by you including a part in the script that tells itself to resume.”, I couldn’t agree with that because, how do you explain that it sometimes resumed by itself without being told. ? I didn’t say that it is not resuming all the time, just sometimes. 50/50 chances.

Again, I apologized for the ruckus. :pray:t2:

It did not resume itself- it did not stop running and there is an important difference.
Whether you agree or not- is not relevant. Should you disagree with me if I say that the Proton has a positive charge, your disagreement will not change the state of the Proton.
A script on the machine Cannot Start without being Told, Instructed, Authorized to do so.
Once it is running, if it fails to stop… then it failed to stop. But that is not the same thing as running, stopping, then starting itself without being instructed to do so.

If you want your script to resume from suspend /Hibernate, every time you wake the computer 100% of the time, you must instruct it do so with your script.

I certainly understand where this can be confusing. It appears to run some of the time without you having to tell it to… And it says within the script that it is supposed to perform an action every second.
However, as I pointed out - If a script could start itself without authorization or instruction- Then all your scripts could be going haywire the moment that you wake or boot up the computer.
As this is not happening, your only rational conclusion must be that the scripts cannot start themselves without instruction or authorization - Even if sometimes, the script is not stopped when you suspend the computer.

I re-read all things you said above, and think about it a little while. Yes, it’s a bit confusing to me ALOT, but I think I begin to grasp the idea.
So, the script that you gave me above, is that for both pausing and resuming the watch command?
And, I still trying to figuring out how to use the script… :thinking:

No, hibernate is the “pause” so to speak. It merely tells the script to resume issuing the command contained within the script upon wake.

I see, and … what does vlock -ans do in the script?

ah, nevermind, I looked it up, so vlock is for virtual locking. I didn’t installed it so it does not do anything to my system.

Good point, you may not have the session lock installed.
I apologize, I can see how that would confuse you. The script I posted was more an Example than a script specific to you.
I am not sure what your script is for or what it is supposed to do.
The link I posted here:


Would probably give better examples that you can use.
Essentially, you want to make a script as the guide teaches, that references the command you want to start and run upon resume.
The script must be placed in /lib/systemd/system-sleep and /usr/lib/systemd/system-sleep

I am not sure what your script is for or what it is supposed to do.
So on my another laptop, I only open 1 terminal, and executed watch -ctn 1 bash myscript.sh, inside it has xidel command for webscrapping, and it showing the data that is updated regularly. Then lastly it prints the date and time. That’s it, the script ends there. The purpose of that laptop is just that, showing the information I need on the screen.

/lib/systemd/system-sleep and /usr/lib/systemd/system-sleep ,both of them?

Question
So, inside that sleep folder has hdparm script, do I create myscript.sh or I just edit that hdparm.sh?

Now, I am the one who is confused. Earlier, you pasted a snippet of your bash script and I actually thought that was all there was to it.
Which, of course, made it no surprise that it was not working on resume. Or doing much of anything else.

I am not trying to be nosy. I only point out that I do not fully know your intentions so I may not be able to give better pointers.
Either way, everything I said above still applied- You need a script that handles “resume from suspend / hibernate” in order to Start Your Script on resume each time.

Yes, Both of Them.

No, do not edit the hdparm script.

You would create a new script- The tutorial I posted above should help you but Please Read it Carefully because making an error in init can cause you major headaches. This is one of those “do it right the first time” things.

I’m sorry about that, I thought every bash script is simple because it can run in the speed of lightning, unlike heavyweight apps.

No, you’re not.

Yes, I will. And… The tutorial mentioning about if-else pre and post ,while your script is using suspend and resume. Which one is more advance? Or is it the same?

So, today I tried the thing.

  1. I couldn’t find a system-sleep folder in /usr/lib/systemd/ so I made one.
  2. I tried a simple script that does not need printout, such as touch file.txt using the if-else method. but when I try to suspend and wake up, nothing happened.
  3. I named the file to post-suspend.sh if that matters, and chmod +x for both of them.
  4. I tried restarting my laptop, nothing happened.

did I miss a step?

Possibly. And I am not sure, either. It is not that often that I use a bash script in this way.
Between the two of us or any other contributors that join the thread, let’s research it more.
The initial question: What is stopping it from starting is, I think addressed. But, the result you want: A working function script, Is Not.
I am sure we’ll get it working. :wink:

Yeah, lets do it. I have a very bad luck in Stack Overflow, I’ll find another way.

I’ve been to another forum for this problem’s enlightment, but it seems I face the dead end. And possibly, the main cause of this problem, is the watch command. I was told to monitor the cause of the freezing using strace command, but this is not the final solution, because it only shows the process whilst the freezing happen randomly, last time it took 8 straight days resuming without freezing. Also, the final cure for this including modify the source code of watch, which happened to be a heavy task for me.

What I do now, is to change the watch command, I substitute it with while command like this:

while : 
do
bash script.sh
sleep 1
done 

I tried this code several times and it does not freeze, I just hope that this does not freeze one day. But since while : is infinite, I wonder if its running under hibernation because the resume seems very fluid.

edit: oh snap, it freeze after some more tries.

1 Like

Quenyen, would you be willing to share the actual scripts involved or send them privately for examination?
Without knowing what the scripts contain or do, it is very hard to diagnose, at all.

sure, here is the script I’ve been using, I sometimes just run it with regular bash command, and sometimes just leave it running with watch command, and you might see clear (line:97) command inside the script because recently I tried the while : command, and it has the purpose of disposing the old data shown on the terminal.

LINK
password: covid19
tools needed: xidel

1 Like