How to run a shell script at startup

前端 未结 21 2030
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 13:39

On an Amazon S3 Linux instance, I have two scripts called start_my_app and stop_my_app which start and stop forever (which in turn runs my

21条回答
  •  野性不改
    2020-11-22 14:00

    Many answers on starting something at boot, but often you want to start it just a little later, because your script depends on e.g. networking. Use at to just add this delay, e.g.:

    at now + 1 min -f /path/yourscript
    

    You may add this in /etc/rc.local, but also in cron like:

    # crontab -e
    @reboot at now + 1 min -f /path/yourscript
    

    Isn't it fun to combine cron and at? Info is in the man page man at.

    As for the comments that @reboot may not be widely supported, just try it. I found out that /etc/rc.local has become obsolete on distros that support systemd, such as ubuntu and raspbian.

提交回复
热议问题