Linux 脚本在启动时不运行

Linux 脚本在启动时不运行

您好,谢谢您的帮助。我正在尝试在启动时运行一个脚本来降低 GPU 的功率限制。 shell 命令位于 init.d 中,我尝试使用 rc1 和 rc3 的符号链接。 shell 命令也可以使用 Chmod +x 来执行。我也在运行 Ubuntu 16.04。当我重新启动计算机时,只有一张卡的瓦数下降到适当的水平,而其他两张卡保持不变。这是gpu0。任何帮助将非常感激。我也尝试过使用 Crontab,但遇到了困难。我的脚本如下:

#!/bin/bash

echo "Run as sudo to lower power-limits."
echo ""

nvidia-smi -i 0 -pl 100
nvidia-smi -i 1 -pl 100
nvidia-smi -i 2 -pl 100

echo ""
echo ""

nvidia-smi

答案1

您可以将完整路径(该脚本实际所在的位置)放入rc.local.当操作系统准备好执行脚本时,您输入的任何内容rc.local都会像 root 用户一样运行(请原谅我的英语不够准确),所以要小心。我给你举个例子:

nano /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

/usr/local/samba/bin/samba_dnsupdate --use-samba-tool
exit 0

这意味着当我的操作系统准备好运行脚本时,它将samba_dnsupdate使用该选项运行--use-samba-tool,并且该脚本实际上位于/usr/local/samba/sbin/

问候

相关内容