Bash 脚本未在启动时执行 [英] Bash script not executing on startup

查看:50
本文介绍了Bash 脚本未在启动时执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 crontab 每天(午夜)运行一次 bash 脚本.这很成功,但我并没有真正考虑清楚,如果我的计算机碰巧在午夜关闭(甚至睡着了),脚本将无法运行.

I used crontab to run a bash script once a day (at midnight). This worked successfully, but I didn't really think it through enough to realise that the script would not run if my computer happened to be off at midnight (or even asleep).

所以我认为我必须保留 crontab 条目(以防我的计算机打开),但我还想让 bash 脚本在启动时执行(以防我的计算机关闭),以便我涵盖所有基础.

So I think that I have to keep the crontab entry (in case my computer is on) but I also want to make the bash script execute on startup (in case my computer was off) so that I have covered all my bases.

我在网上看到要在启动时执行我的脚本,我应该编辑我的 /etc/rc.local 文件.我的文件现在包含:

I saw online that to have my script execute on startup I should edit my /etc/rc.local file. My file now contains:

#! /bin/bash                                                                    
bash /home/me/code.sh
exit 0

我的权限是-rwxr-xr-x.

但是,脚本不会在启动时执行.我做错了什么吗?

However, the script does not execute on startup. Is there something I'm doing wrong?

推荐答案

我猜你自己创建了/etc/rc.local 吧?AFAIK Ubuntu 18.04 中没有了(因为它已被弃用).这可能就是它没有被执行的原因.

I guess you created the /etc/rc.local yourself right? AFAIK there isn't any in Ubuntu 18.04 anymore (as it is depricated). That's probably why it's not executed.

crontab 中的@reboot 可能是您问题的可能解决方案.

@reboot in crontab might be a possible solution for your problem.

这篇关于Bash 脚本未在启动时执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆