bash - echo: write error: invalid argument

norman

I am new to bash and trying to write a script that disables 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 is going on here? I thought $i was just the file name, which seems like the correct syntax for echo.

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

Update: With set -vx added to the top of the script, here is a problematic iteration:

+ 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
MajorT

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

bash: echo: write error: Invalid argument

From Dev

"echo: write error: invalid argument" writing to sysfs

From Dev

cat: write error: Invalid argument

From Dev

sed and tac: write error: Invalid argument

From Dev

bash: echo: write error: No space left on device

From Dev

bash: echo: write error: Interrupted system call

From Dev

bash: echo: write error: No space left on device

From Dev

Trying to write to /sys/class/gpio/export – write error: Invalid argument

From Dev

Echoing an echo argument in Bash

From Dev

R Write.CSV Error: Cannot Open File, Invalid Argument

From Dev

Bash Script: Invalid argument

From Dev

waitid() error: invalid argument

From Dev

Error:Invalid Argument

From Dev

Invalid argument error with NSMutableString?

From Dev

Invalid Argument Error

From Dev

Invalid 'length' argument Error

From Dev

Bash script echo error

From Dev

Git push results in "fatal: sha1 file '<stdout>' write error: Invalid argument" error

From Dev

error: invalid type argument of unary '*'

From Dev

connection error: Invalid argument at sockets

From Dev

VBA; Invalid procedure or argument error

From Dev

Invalid postback or callback argument error

From Dev

Bind failed with Invalid argument error

From Dev

highcharts - error in IE - Invalid Argument

From Dev

error: invalid type argument of unary '*'

From Dev

Invalid argument error in httptunnel client

From Dev

Error unmounting Docker - invalid argument

From Dev

How write argument null exception and invalid exception?

From Dev

invalid argument in bash script when port is bad