【问题标题】:execute script with parameters on linux boot [closed]在linux启动时执行带有参数的脚本[关闭]
【发布时间】:2018-04-16 17:31:53
【问题描述】:

我正在使用基于LinuxDebian。有一个需要在启动时执行的脚本。找到these instructions describing on how it needs to be one。我唯一的区别是我需要在启动时运行带有参数的脚本(myscript.sh --some-option 23)。我不能使用包装脚本。我不会解释为什么,但我只会说我不能。有谁知道该怎么做?

【问题讨论】:

  • /etc/rc.local运行它?为systemd创建一个服务单元来运行它?
  • 你的系统使用systemd吗? (例如,运行systemctl 成功了吗?)

标签: linux startup boot


【解决方案1】:

假设您使用的是带有 systemd 的系统,这很容易。创建一个新的服务文件“foo.service”:

[Unit]
Description=Powertop autotune

[Service]
ExecStart=/usr/sbin/powertop --auto-tune # XXX replace with your command

[Install]
WantedBy=multi-user.target

然后安装它:

ln -s /home/kris/Scripts/systemd/powertop.service /lib/systemd/system
systemctl enable powertop
systemctl start powertop

显然你的路径和细节会有所不同。特别是,/lib/systemd/system 可能不是您的发行版中的正确位置。

【讨论】:

    【解决方案2】:

    cron 守护程序有一个@reboot 命令。这会在重新启动时运行您的脚本。因此,只需编辑您的 crontab 并添加如下一行:

    @reboot /your/script/test.sh
    

    【讨论】:

    • cron 守护程序在我的系统上不可用。
    • @flashburn 是什么阻止您安装某种 cron?
    猜你喜欢
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-04
    • 2015-03-15
    • 2011-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多