这是真的吗,为了使设置在Linux系统中永久化,批处理脚本方式是标准的?
今天,我发现自己检查计算机唤醒设置在重新启动计算机后被重置。我开始搜索Google,我需要设置一个批处理脚本,以便这些更改能够持久存在。现在,这种建议在这类“罕见的配置”中是普遍的。这让我非常紧张,因为没有人谈论任何配置或负责唤醒功能的软件,相反,一些看似廉价的批处理脚本解决方案被抛入其中,这些解决方案应该设置计算机启动时的设置。
是否必须设置批处理脚本,并且在/etc/或任何其他文件夹中没有用于唤醒的配置来设置关闭或重新启动后保存的永久更改?
我正在提供更多信息:
naudotojas@naudotojas-N53SV:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 19.04
Release: 19.04
Codename: disco
naudotojas@naudotojas-N53SV:~$ 我希望在重新启动Ubuntu之后禁用的These设置,也就是保持永久状态:
naudotojas@naudotojas-N53SV:~$ cat /proc/acpi/wakeup | grep enabled
EHC1 S3 *enabled pci:0000:00:1d.0
EHC2 S3 *enabled pci:0000:00:1a.0
XHCI S3 *enabled pci:0000:04:00.0<#>This是我希望在重新启动后看到的最后结果:
EHC1 S3 *disabled pci:0000:00:1d.0
EHC2 S3 *disabled pci:0000:00:1a.0
XHCI S3 *disabled pci:0000:04:00.0发布于 2021-02-15 15:39:13
这样做的首选方法是使用systemd创建一个service。在rc.local中添加脚本是不推荐的方式。
~/scripts/disable-devices-as-wakeup.sh.#!/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$ touch ~/scripts/disable-devices-as-wakeup.service~/脚本/禁用-设备即唤醒服务-
[Unit]
Description=Disable devices as wakeup
[Service]
ExecStart=/home/username/scripts/disable-devices-as-wakeup.sh
Type=oneshot
[Install]
WantedBy=multi-user.target/etc/systemd/system/。$ sudo cp ~/scripts/disable-devices-as-wakeup.service /etc/systemd/system/$ systemctl enable disable-devices-as-wakeup.service$ systemctl status disable-devices-as-wakeup.service在https://access.redhat.com/documentation/en-us/red_帽子_企业_linux/7/html/system_管理员_指南/章-管理_服务_使用_系统d上找到详细的解释
发布于 2021-04-15 20:38:34
非常感谢你的解释,希希凯什。我在我的系统里用过这个。虽然代码中有一个小错误。我不是一个程序员,但其他人指出了这一点。因此,供其他人参考。第一行中不应该有引号。它应该是:
#!/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或者“启用”就是你想要达到的目标。
https://askubuntu.com/questions/1146264
复制相似问题