Starting script on boot as root
Hello,
I'm trying to start a script with root permissions upon boot, but everything i tried so far isn't working. First, I tried using crontab with @reboot option. Then i tried using /etc/init.d technique, but I'm not seeing the process running. To give you little more information about the specific steps: 1) Created script called test.sh Code:
#! /bin/bash 3) Created startup.sh under /etc/init.d/ Code:
#! /bin/bash 5) Added symlink Code:
sudo ln -s /etc/init.d/startup.sh /etc/rc0.d/ |
If you posted an exact copy of your script it contains errors and will not run.
Quote:
while [[ $i -lt 100 ]] The easiest way to get your script running is using cron or rc.local in my opinion. What version of Mint are you running? |
Yes, you are right! It was a typo, i have no issue with the script it self, but still trying to figure out how to start the script at boot with root privileges.
|
why do you think it was not running?
|
Did you use sudo to add your job to roots crontab?
sudo crontab -e |
Yes, i ran:
Code:
sudo crontab -e Code:
@reboot root /home/mist/Documents/test.sh 40 & |
You only need to specify the user (i.e root) when adding a system cron job in the /etc/cron directories.
Try sudo crontab -e @reboot /home/mist/Documents/test.sh 40 & |
still did not explain how did you check if that process was running?
|
I just tried that and no luck so far.
|
No luck that it isn't running or not running as root?
|
@michaelk
The script is not even starting. I read somewhere(forgot where) that @reboot doesn't work anymore. @pan64 After reboot, i run ps -ef | grep test |
The @reboot works - but you need to look at the logs to see what happened.
One of the potential issues depends on whether you are using systemd or not, and how /home or /home/mist are mounted. In some cases the cron service starts before the network is ready... and that could mean that NFS mounts haven't been done yet. What I'm not sure of is whether even all the local mounts have been done yet. I think they are supposed to have been completed, but don't know for sure. |
@jpollard
Code:
sudo stat /proc/1/exe Code:
grep CRON /var/log/syslog | grep "Nov 15" |
I don't have anything running Mint at the moment but @reboot does work on my systems that do use systemd.
You can verify that your entry is actually added by looking roots /var/spool/cron/crontabs file. Also make sure that you have a line feed character at the end of the entry. Go back and edit the crontab, move the cursor to the end of the line and press the enter key. Save crontab. |
@michaelk
Code:
mist-vm crontabs # pwd Code:
sh /home/mist/Documents/test.sh 40 & |
All times are GMT -5. The time now is 11:27 AM. |