Bash - echo: write error: invalid argument

I am new to bash and am trying to write a script that shuts down the kworker business as in aMaia's answer here .

So far, I have this, which I run from root:

  1 #!/bin/bash                                                                      
  2                                                                                  
  3 cd /sys/firmware/acpi/interrupts                                                 
  4 for i in gpe[[:digit:]]* # Don't mess with gpe_all                               
  5 do                                                                               
  6     num=`awk '{print $1}' $i`                                                    
  7     if (( $num >= 1000 )); then  # potential CPU hogs?                           
  8         # Back it up and then disable it!!                                       
  9         cp $i /root/${i}.backup                                                  
 10         echo "disable" > $i                                                      
 11     fi                                                                           
 12 done  

      

But running it results in:

./kkiller: line 10: echo: write error: Invalid argument

      

What's going on here? I thought $i

it was just a filename that looks like the correct syntax for echo.

Suggestions for cleaning / improving the script in general are also welcome!

Update: if set -vx

added to the beginning of the script, there is an iterative issue here:

+ for i in 'gpe[[:digit:]]*'
awk '{print $1}' $i
++ awk '{print $1}' gpe66
+ num=1024908
+ ((  1024908 >= 1000  ))
+ cp gpe66 /root/gpe66.backup
+ echo disable
./kkiller: line 10: echo: write error: Invalid argument

      

+5


source to share


4 answers


I think he has something with permissions. I don't think root has write permissions to these files by default. Try to echo manually disable this file even if root you get the same error. So to make your script work, first do chmod 744 on $ i before your echo, it should do the trick.



0


source


I also had this issue in Docker on Alpine linux environment. I think the problem is that echo puts a newline at the end of the line by default, and the kernel doesn't accept it, but this is not the case on every system. In Docker, I had this error, but the value was written despite the error message.



Solution (in Bash): echo -n disable >/sys/firmware/acpi/interrupts/gpe66

. Thus, no newline character is repeated.

+6


source


Double spell check. echo "disabled" will cause a write error even for root, while echo "disable" succeeds.

+3


source


I got the same error while trying to disable a GPE that was already disabled:

# echo "disable" > /sys/firmware/acpi/interrupts/gpe17
-su: echo: write error: Invalid argument
# cat /sys/firmware/acpi/interrupts/gpe17
 3718289     STS disabled     unmasked

      

Once enabled, I could disable it without error:

# echo "enable" > /sys/firmware/acpi/interrupts/gpe17
# echo "disable" > /sys/firmware/acpi/interrupts/gpe17
# 

      

0


source







All Articles