The officially official Devuan Forum!

You are not logged in.

#1 2021-04-14 15:00:18

Altoid
Member
Registered: 2017-05-07
Posts: 1,429  

[SOLVED] Help with script

Hello:

My /proc/acpi/wakeup file reads thus:

groucho@devuan:/proc/acpi$ cat wakeup
Device	S-state	  Status   Sysfs node
USB0	  S4	*enabled   pci:0000:00:1d.0
USB1	  S4	*enabled   pci:0000:00:1d.1
USB2	  S4	*enabled   pci:0000:00:1d.2
USB5	  S4	*disabled
EUSB	  S4	*enabled   pci:0000:00:1d.7
USB3	  S4	*enabled   pci:0000:00:1a.0
USB4	  S4	*enabled   pci:0000:00:1a.1
USB6	  S4	*enabled   pci:0000:00:1a.2
USBE	  S4	*enabled   pci:0000:00:1a.7
P0P1	  S4	*disabled  pci:0000:00:01.0
P0P2	  S4	*disabled  pci:0000:00:06.0
P0P3	  S4	*disabled  pci:0000:00:1c.0
BR11	  S4	*disabled
BR12	  S4	*disabled
BR13	  S4	*disabled
P0P4	  S4	*disabled  pci:0000:00:1c.4
BR15	  S4	*disabled
P0P5	  S4	*disabled  pci:0000:00:1e.0
GBE	  S4	*enabled   pci:0000:00:19.0
SLPB	  S4	*disabled
groucho@devuan:/proc/acpi$ 

I have no use for anything being enabled there and found a script to set everything to 'disabled':

See: https://gist.github.com/npcardoso/47d8f … wakeups-sh

#!/bin/bash
 
if [[ $# > 1 || ($1 != "enable" && $1 != "disable") ]]; then
         echo "Usage: $0 <enable|disable>"
         exit 1
fi

if [[ $1 == "enable" ]]; then
        TOGGLE=grep '\*disabled' /proc/acpi/wakeup | cut -d ' ' -f1

else

        TOGGLE=grep '\*enabled' /proc/acpi/wakeup | cut -d ' ' -f1

fi

for DEV in $TOGGLE; do
        echo $DEV 
        echo $DEV > /proc/acpi/wakeup

done

For some reason it is not running properly.

groucho@devuan:~$ ./acpi_wakeups.sh disable
./acpi_wakeups.sh: line 14: \*enabled: command not found
groucho@devuan:~$ 
groucho@devuan:~$ ./acpi_wakeups.sh enable
./acpi_wakeups.sh: line 10: \*disabled: command not found
groucho@devuan:~$ 

Any help would be appreciated.

Thanks in advance,

A.

Last edited by Altoid (2021-04-14 15:05:09)

Offline

#2 2021-04-14 15:25:54

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: [SOLVED] Help with script

I believe that script would need to be run as the root user ?

Offline

#3 2021-04-14 15:47:54

Altoid
Member
Registered: 2017-05-07
Posts: 1,429  

Re: [SOLVED] Help with script

Hello:

dice wrote:

... need to be run as the root user?

Yes, of course.

groucho@devuan:~$ sudo ./acpi_wakeups.sh enable
./acpi_wakeups.sh: line 10: \*disabled: command not found
groucho@devuan:~$ 
groucho@devuan:~$ sudo ./acpi_wakeups.sh disable
./acpi_wakeups.sh: line 14: \*enabled: command not found
groucho@devuan:~$ 

Just in case ...

[root@devuan ~]# /home/groucho/acpi_wakeups.sh enable
/home/groucho/acpi_wakeups.sh: line 10: \*disabled: command not found
[root@devuan ~]# 
[root@devuan ~]# /home/groucho/acpi_wakeups.sh disable
/home/groucho/acpi_wakeups.sh: line 14: \*enabled: command not found
[root@devuan ~]# 

Thanks for your input.

Best,

A.

Offline

#4 2021-04-14 16:39:12

chris2be8
Member
Registered: 2018-08-11
Posts: 265  

Re: [SOLVED] Help with script

https://gist.github.com/npcardoso/47d8f … wakeups-sh has backticks round grep '\*disabled' /proc/acpi/wakeup | cut -d ' ' -f1 and grep '\*enabled' /proc/acpi/wakeup | cut -d ' ' -f1. Those tell bash to run the command inside the backticks and assign the output from it to TOGGLE.

You could use $(...) instead, it's easier to read if you don't get muddled about what sort of brackets to use.

Chris

Offline

#5 2021-04-14 16:46:30

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: [SOLVED] Help with script

Use https://www.shellcheck.net/ to test scripts. That would have identified the problem along with several other issues.

Better version:

#!/bin/sh
 
if [ $# -gt 1 ] || [ "$1" != enable ] && [ "$1" != disable ]; then
         echo "Usage: $0 <enable|disable>"
         exit 1
fi

if [ "$1" = enable ]; then
        TOGGLE=$(grep '\*disabled' /proc/acpi/wakeup | cut -d ' ' -f1)

else

        TOGGLE=$(grep '\*enabled' /proc/acpi/wakeup | cut -d ' ' -f1)

fi

for DEV in $TOGGLE ; do
        echo "$DEV" 
        echo "$DEV" > /proc/acpi/wakeup

done

POSIX sh ftw!

It can be simplified further if all you want to do is disable everything:

#!/bin/sh

dev=$(awk '/*enabled/{print $1}' /proc/acpi/wakeup)

for i in $dev ; do
   echo "$i" > /proc/acpi/wakeup
done

Brianna Ghey — Rest In Power

Offline

#6 2021-04-14 18:25:09

Altoid
Member
Registered: 2017-05-07
Posts: 1,429  

Re: [SOLVED] Help with script

Hello:

chris2be8 wrote:

... use $(...) instead, it's easier to read if you don't get muddled about what sort of brackets to use.

I am not the author of the script.
Unfortunately, I don't have a clue as to how this all works.

Thanks for your input.

Best,

A.

Offline

#7 2021-04-14 18:47:08

Altoid
Member
Registered: 2017-05-07
Posts: 1,429  

Re: [SOLVED] Help with script

Hello:

Head_on_a_Stick wrote:

Use https://www.shellcheck.net/ to test scripts.

Thanks for the heads up.
Will bookmark that one for the next time.

Being a script from github, I assumed an error of some sort at my end.
As it seemed harmess enough, I just copied it, made it executable and tried it.
Never thought it would have a problem.

Head_on_a_Stick wrote:

Better version:

#!/bin/sh
 
if [ $# -gt 1 ] || [ "$1" != enable ] && [ "$1" != disable ]; then
         echo "Usage: $0 <enable|disable>"
         exit 1
fi

if [ "$1" = enable ]; then
        TOGGLE=$(grep '\*disabled' /proc/acpi/wakeup | cut -d ' ' -f1)

else

        TOGGLE=$(grep '\*enabled' /proc/acpi/wakeup | cut -d ' ' -f1)

fi

for DEV in $TOGGLE ; do
        echo "$DEV" 
        echo "$DEV" > /proc/acpi/wakeup

done

Right.

Head_on_a_Stick wrote:

POSIX sh ftw!

Don't quite follow you, but I'll take your word for it.  8^)

Head_on_a_Stick wrote:

... simplified further if all you want to do is disable everything:

Yes, that would be much better.
These /proc/acpi/wakeup settings are from S4, which my box doesn't ever/won't ever go into.
And seeing how flaky ACPI tables can be, it's better to keep this disabled.

Head_on_a_Stick wrote:
#!/bin/sh

dev=$(awk '/*enabled/{print $1}' /proc/acpi/wakeup)

for i in $dev ; do
   echo "$i" > /proc/acpi/wakeup
done

Works a charm!  8^D

groucho@devuan:~$ sudo ./acpi_wakeups.sh
[sudo] password for groucho: 
groucho@devuan:~$ 
groucho@devuan:~$ cat /proc/acpi/wakeup
Device	S-state	  Status   Sysfs node
USB0	  S4	*disabled  pci:0000:00:1d.0
USB1	  S4	*disabled  pci:0000:00:1d.1
USB2	  S4	*disabled  pci:0000:00:1d.2
USB5	  S4	*disabled
EUSB	  S4	*disabled  pci:0000:00:1d.7
USB3	  S4	*disabled  pci:0000:00:1a.0
USB4	  S4	*disabled  pci:0000:00:1a.1
USB6	  S4	*disabled  pci:0000:00:1a.2
USBE	  S4	*disabled  pci:0000:00:1a.7
P0P1	  S4	*disabled  pci:0000:00:01.0
P0P2	  S4	*disabled  pci:0000:00:06.0
P0P3	  S4	*disabled  pci:0000:00:1c.0
BR11	  S4	*disabled
BR12	  S4	*disabled
BR13	  S4	*disabled
P0P4	  S4	*disabled  pci:0000:00:1c.4
BR15	  S4	*disabled
P0P5	  S4	*disabled  pci:0000:00:1e.0
GBE	  S4	*disabled  pci:0000:00:19.0
SLPB	  S4	*disabled
groucho@devuan:~$ 

Thank you very much for your input.

Best,

A.

Offline

#8 2021-04-14 19:12:13

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: [SOLVED] Help with script

Altoid wrote:

Never thought it would have a problem.

The script on GitHub does actually have the backticks, you must have missed them when you copied it.

Altoid wrote:
Head_on_a_Stick wrote:

POSIX sh ftw!

Don't quite follow you

The original script used bash but didn't contain anything that actually needed bash. The tests ([[...]]) were the bash version but the /bin/sh (POSIX) test ([...]) works just as well. I always prefer /bin/sh over /bin/bash because it's faster, lighter and less buggy. The Debian developers also prefer /bin/sh for the same reasons and went to quite some effort replacing all of the bash system scripts with /bin/sh versions. Ubuntu also did this: https://wiki.ubuntu.com/DashAsBinSh

Last edited by Head_on_a_Stick (2021-04-14 19:12:43)


Brianna Ghey — Rest In Power

Offline

#9 2021-04-14 19:25:36

Altoid
Member
Registered: 2017-05-07
Posts: 1,429  

Re: [SOLVED] Help with script

Hello:

Head_on_a_Stick wrote:

... you must have missed them when you copied it.

Painted short, probably?
Have to be more careful.

Head_on_a_Stick wrote:

... script used bash but didn't contain anything that actually needed bash.

I see.

Head_on_a_Stick wrote:

... prefer /bin/sh over /bin/bash because it's faster, lighter and less buggy.
The Debian developers also prefer /bin/sh for the same reasons and went to quite some effort replacing all of the bash system scripts with /bin/sh versions.

Kudos to them.
Thanks for taking the time to explain.

Best,

A.

Offline

Board footer