LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 04-15-2021, 02:47 PM   #1
giesbert
Member
 
Registered: Aug 2003
Location: The Netherlands
Distribution: Debian 12
Posts: 57

Rep: Reputation: 12
Post How to set 2 acpi settings to enabled on a laptop via bash script at boot


I've Ubuntu 20.10 running on a laptop.
It is running very well, but I still have a small issue with power management. When I close the lid, the laptop suspends. But when I open it, it does not wake up.
I want to echo LID0 and XHC1 to /proc/acpi/wakeup when one or both of them are disabled.

I've found a script, that was working wel for others. This is the original script:
Code:
#!/bin/bash

declare -a devices=("EHC1 EHC2 XHCI") # <-- Add your entries here
for device in "${devices[@]}"; do
    if grep -qw ^$device.*enabled /proc/acpi/wakeup; then
        sudo sh -c "echo $device > /proc/acpi/wakeup"
    fi
done
In: "cat /proc/acpi/wakeup" these are the XHC1 and LID0 items:
Code:
XHC1      S3    *disabled   pci:0000:00:14.0 
LID0      S4    *disabled  platform:PNP0C0D:00
I changed the script like this:
Code:
#!/bin/bash
declare -a devices=("XHC1 LID0")
for device in "${devices[@]}"; do
    if grep -qw ^$device.*disabled /proc/acpi/wakeup; then
        sudo sh -c "echo $device > /proc/acpi/wakeup"
    fi
done
But than I get this error:
Code:
grep: LID0.*disabled: File or folder does not exist
When I change the code like this:
Code:
declare -a devices=("XHC1")
so by removing 1 device, then the code works.

Can someone help me solve this script problem?

Last edited by giesbert; 04-15-2021 at 03:59 PM. Reason: made it more clear and simple
 
Old 04-15-2021, 04:06 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,512

Rep: Reputation: 6223Reputation: 6223Reputation: 6223Reputation: 6223Reputation: 6223Reputation: 6223Reputation: 6223Reputation: 6223Reputation: 6223Reputation: 6223Reputation: 6223
Code:
array_name=( element_1 element_2 element_N )
Code:
declare -a devices=("EHC1 EHC2 XHCI")
Im guessing it was a syntax error that was never corrected. The generic way to define an array is each element separated by a space. However, since all the elements are enclosed with quotes it is treated as a single element.

Code:
#!/bin/bash

declare -a devices=("EHC1 EHC2 XHCI") # <-- Add your entries here
echo "Number of elements = ${#devices[@]}"
 
Old 04-15-2021, 04:28 PM   #3
giesbert
Member
 
Registered: Aug 2003
Location: The Netherlands
Distribution: Debian 12
Posts: 57

Original Poster
Rep: Reputation: 12
Cool

Quote:
Originally Posted by michaelk View Post
Code:
array_name=( element_1 element_2 element_N )
Code:
declare -a devices=("EHC1 EHC2 XHCI")
Im guessing it was a syntax error that was never corrected. The generic way to define an array is each element separated by a space. However, since all the elements are enclosed with quotes it is treated as a single element.

Code:
#!/bin/bash

declare -a devices=("EHC1 EHC2 XHCI") # <-- Add your entries here
echo "Number of elements = ${#devices[@]}"
Super! I think that was the issue! I have to remove the quotes! If I change the script like this:
Code:
#!/bin/bash

declare -a devices=( LID0 XHC1 )
for device in "${devices[@]}"; do
    if grep -qw ^$device.*disabled /proc/acpi/wakeup; then
        sudo sh -c "echo $device > /proc/acpi/wakeup"
    fi
done
I'm able to switch both items to enabled! Just by removing the quotes.
Thank you very much michaelk
 
  


Reply

Tags
acpi, bash script, laptop, powermanagement


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to watch videos from Laptop on 'TV with USB enabled set-top-box'. Anil Kagi Linux - Newbie 3 01-22-2016 11:41 PM
Connect my non wireless enabled pc to my wireless enabled pc via ethernet? Help me im dumb Linux - Networking 3 10-21-2012 05:58 PM
[sda] Write cache: enabled, read cache: enabled, doesn't support DPO seskissinger Linux - Software 3 05-16-2008 02:17 PM
Notebook freezes on boot with ACPI enabled maddoug Linux - Laptop and Netbook 12 04-14-2004 11:53 PM
SuSE 8.1 under generic, acpi enabled kernel Hcman Linux - Distributions 1 02-10-2003 06:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 03:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration