如何在 Ubuntu 机器启动时运行脚本?

Ale*_*lex 10 linux boot script python ubuntu

我想运行 /home/myuser/go.py

每次我的 linux 机器启动时,我如何让它在后台运行?

ken*_*orb 10

简单的方法

您可以将此脚本添加到/etc/rc.local文件中(exit行前),例如

/home/myuser/go.py &
Run Code Online (Sandbox Code Playgroud)

&在年底会在后台运行的脚本。

确保你有执行标志。要测试它,只需从终端运行:

sh /etc/rc.local
Run Code Online (Sandbox Code Playgroud)


小智 5

您可以在目录中放置一个脚本/etc/init.d/(例如:/etc/init.d/go.py),用于在启动时运行任何您想要运行的内容。

http://www.debian-administration.org/article/Making_scripts_run_at_boot_time_with_Debian

  • 我更喜欢 `/etc/rc.local` 因为您不需要更改运行级别链接。 (9认同)
  • 也许您应该将其添加为单独的答案,以便可以对其进行投票? (2认同)