Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

There are two ways to do this I currently use.

A) Use Crontab in conjuction with @reboot (I use this to run a command as a specific user because each user gets a crontab)

crontab -e

Crontab Example

 @reboot echo "hello" > /root/hello.sh

B) Edit /etc/rc.local (The purpose of rc.local is to run commands at boot, but they are run as root user)

1st make sure /etc/rc.local has correct permissions (I think it is purposely set to not executable by default)

It should look like:

ls -la /etc/rc.local
-rwxr-xr-x 1 root root 395 Oct 23 19:47 /etc/rc.local 

To set permissions:

sudo chown root /etc/rc.local && sudo chmod 755 /etc/rc.local 

Then just:

sudo nano /etc/rc.local 

Make the bottom look like this:

/root/.reboot.sh

exit 0 

And make sure not to delete the notes(#'s), especially the "shebang"!

#!/bin/sh -e 

Now just put script/scripts into

sudo nano /root/.reboot.sh && sudo chmod 755 /root/.reboot.sh 

To test use:

sudo /etc/init.d/rc.local start 

RCLocal Long Prep CMD:

sudo chown root /etc/rc.local && sudo chmod 755 /etc/rc.local && sudo nano /etc/rc.local && sudo sh -c 'echo "#!/bin/bash" >> /root/.reboot.sh' && sudo chmod 755 /root/.reboot.sh 

Now you can just edit /root/.reboot.sh whenever and reboot and it should work.

  • No labels