1

I was trying to run a .sh script on my OpenBSD machine on startup.

I've made the script executable using the chmod +x command. I've also added the script to cron via an entry reading

@reboot sh /dir/myscript.sh

(no quotes) as well as adding the script via and entry to /etc/rc.d/rc.local and making that executable as well, to no avail.

The script is a basic echo "hello" command. Any tips?

Note: I edited restart to reboot, as I misremembered exactly what I typed in

3
  • 3
    Where do you expect to see this hello string? If running correctly (with @reboot, not @restart), you would get the string mailed to you. If running from /etc/rc.local (note the path), you would see it during boot.
    – Kusalananda
    Oct 8, 2021 at 9:43
  • 1
    Also, to what crontab did you add your command?
    – Kusalananda
    Oct 8, 2021 at 9:50
  • You have updated your question and corrected the @restart tag in your crontab. You still don't say what happens when this runs though. The owner of the crontab should get an email with the output of the job, including any error messages. If this happens, can we assume that the issue has been resolved (and that GADR3's answer was correct, and that you may accept that as the correct solution)?
    – Kusalananda
    Oct 9, 2021 at 13:27

1 Answer 1

2

To run a command on startup via crontab, you should use @reboot string:

see info crontab or man 5 crontab.

    string         meaning
    ------         -------
    @reboot        Run once, at startup.
3
  • man 5 crontab instead of info crontab, as the latter says nothing about @reboot on my OpenBSD 7.0 machine Jan 30, 2022 at 16:52
  • @uxer Thanks, I have edited my answer.
    – GAD3R
    Jan 31, 2022 at 19:40
  • Also note that the user who owns the crontab would expect to get an email if the script produces any output or errors (they say they use a simple echo "hello" script).
    – Kusalananda
    Jan 31, 2022 at 20:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .