4

I searched this website and Google but couldn't find it.. How can I execute two (or more) commands using @reboot ?

What I have now:

@reboot /root/website1/starter.sh

What I want:

@reboot /root/website1/starter.sh
@reboot /root/website2/starter.sh

Is this correct or should I solve it otherwise?

Thanks in advance :)

  • It would probably be helpful to know what distro of Unix/Linux you're using. In the meantime, you might try putting both commands in a shell script and simply invoking that script from \@reboot. – zpletan Dec 22 '15 at 19:29
  • "Is this correct?" Does it work? – a CVn Dec 22 '15 at 19:55
4

Yes, that is the correct approach.

You could also reduce it to a single line, as such:

@reboot /root/website1/starter.sh && /root/website2/starter.sh

Just keep in mind that the scripts will run consecutively (not concurrently), and the second script will only run if the first script/command exits successfully. If the second script should run regardless of the result of the previous script, separate the commands with a semi-colon instead of &&.

If you need the scripts to run in parallel, you should stick with your original approach (one command/script on each line).

The double-ampersand (&&) can also be used in the "command" section to run multiple commands consecutively, but only if the previous command exits successfully. A string of commands joined by the double-ampersand will only get to the last command if all the previous commands are run successfully. If exit error-checking is not of a concern, string commands together, separated with a semi-colon (;)

CronHowto - Crontab Example

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.