我是 bash 的新手,正在尝试编写一个禁用 kworker 业务的脚本,如 aMaia 的回答 here .
到目前为止,我有这个,我从 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
但是运行它会导致:
./kkiller: line 10: echo: write error: Invalid argument
这是怎么回事?我以为 $i
只是文件名,这似乎是 echo 的正确语法。
也非常感谢有关清理/改进脚本的建议!
更新:将 set -vx
添加到脚本的顶部,这是一个有问题的迭代:
+ 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
最佳答案
我在 Alpine linux 环境下的 Docker 中也遇到了这个问题。我认为问题在于默认情况下 echo 在字符串末尾放置一个换行符,内核不接受它,但并非每个系统都是如此。在 Docker 中我遇到了这个错误,但是尽管有错误消息,该值还是被写入了。
解决方案(在 Bash 中):echo -n disable >/sys/firmware/acpi/interrupts/gpe66
。这样就不会回显换行符。
关于bash-回显 : write error: invalid argument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27734792/