我想在每次启动时运行一个命令(关闭蓝牙设备)。我通常使用 cron 来执行这些操作,但这是一个需要以 root 身份运行的命令。我该怎么做呢?
您仍然可以使用 cron 来执行此操作。
像这样在 /etc/crontab 中创建一个条目
@reboot root /path/to/your/command
Run Code Online (Sandbox Code Playgroud)
或作为根类型
crontab -e
Run Code Online (Sandbox Code Playgroud)
并进行如下尝试:
@reboot /path/to/your/command
Run Code Online (Sandbox Code Playgroud)
/etc/crontab 是全局 crontab,因此您需要指定用户,crontab -e 调用每用户 crontab。