Suspend/Hibernate/Resume/Thaw - Scripts

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
nissse

Suspend/Hibernate/Resume/Thaw - Scripts

Post by nissse »

I need to run a script on a Suspend/Hibernate and on a Resume/Thaw. Now, I know the place to put the script is /etc/pm/sleep.d/ but this doesn't seem to work for a script requiring access to the network as the network is either already down or not up yet when it runs.

Basically, I just need to send out a curl command like:

Code: Select all

curl --data "Asus-Pundit=OFF" http://192.168.0.1:8098/index.html
the command is working if i type it in terminal
I can see in the log (pm-suspend.log) that it is being executed but gives error "curl: (7) Couldn't connect to server" I guess because the network is already down
I have named the file "0000_suspend"

This works perfect in linux mint cinnamon and KDE but when I do the same in linux Mint Xfce it don't work. What is different in Mint XFCE ???

I have tried different distros and this is the result

Not working:
Ubuntu 14.04
Lubuntury 14.04
Elementa os 0.3
Deepin linux
Linux Mint Xfce rebecca

Working:
Linux Mint Cinnamon rebecca
Linux Mint KDE rebecca
LXLE 14.04.2

Is there some smart person that know what can be the difference in the working distros. Maybe different network manager ? or power manager ?
I want to use Linux Mint Xfce.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
UltramaticOrange

Re: Suspend/Hibernate/Resume/Thaw - Scripts

Post by UltramaticOrange »

Try enabling "wake on lan" for your machine. WoL should prevent your network card from being powered down when going into suspend.

If that fails, I think I'd add --retry 5 (to retry 5 times) --retry-delay 5 (to wait 5 seconds between retries). Network should be back up by the end of that time. Of course, that only helps on the boot up, but you could update your script to also send the date+time of the event and send both events when the machine comes back up.
nissse

Re: Suspend/Hibernate/Resume/Thaw - Scripts

Post by nissse »

Thank you for your reply UltramaticOrange
I will try that as soon as I come back from work.
Will post back with thew result when i have test
nissse

Re: Suspend/Hibernate/Resume/Thaw - Scripts

Post by nissse »

The NIC already had WOL enabled and static IP so no luck there.

What I did notice was the script runs fine when using:

sudo pm-suspend

But not if I suspend the computer using the suspend button in xfce or and distro listed in the "Not working" list
Are xfce using some other command to suspend the computer ?
WharfRat

Re: Suspend/Hibernate/Resume/Thaw - Scripts

Post by WharfRat »

nissse,

Check if you have a file /etc/acpi/events/powerbtn. It calls /etc/acpi/powerbtn.sh for processing the power event.

However in that script if there is a login daemon running it should handle the power button and the script exits.

Code: Select all

# If logind is running, it already handles power button presses; desktop
# environments put inhibitors to logind if they want to handle the key
# themselves.
if pidof systemd-logind >/dev/null; then
    exit 0
fi
I found power management to be a tangled mess :?
Locked

Return to “Scripts & Bash”