0

Might have been asked previously, but I can't find a link. How do I make a bunch of commands run as root on startup without having to open the terminal or entering the password?

1 Answers1

2

One way you can try it is by adding your commands to the /etc/crontab file with the @reboot command.

If you run the following command it will load up the file in an editor so you can add the line(s)

sudoedit /etc/crontab

Then how I did it was like so:

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --repo$
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --repo$
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --repo$
@reboot         root    /home/terrance/cb_update.bsh
05 1    * * *   root    /home/terrance/cb_update.bsh
#

As you can see my second to last line starts every time the system restarts @reboot then as the root user with my command of /home/terrance/cb_update.bsh. The last line starts at 01:05 in the morning everyday running that script as the root user.

Hope this helps!

Terrance
  • 41,612
  • 7
  • 124
  • 183
  • That second-to-last line broke my server. I think it keeps running the command in rapid succession. – xendi Dec 11 '19 at 03:22
  • @xendi What command are you talking about? The @reboot is supposed to only run whatever command / script you have one time and that is it. You may want to ask a new question with the contents of the script / command that you are trying to run at startup and why you think it is running over and over again. – Terrance Dec 11 '19 at 04:41