On boot cronjob doesn't get executed properly

Ywa

Verified User
Joined
Feb 4, 2010
Messages
37
Location
The Netherlands
Good day,

I've defined a "@reboot" cronjob via DirectAdmin because I want a script to be started on boot. When I view the cron log it does get started, however, the script doesn't seem to do what it should. Is there something wrong with my command? It only needs execution rights for my user, right?

Command:
Code:
cd ~/app/ && ./forever_start.sh
(I'm first using 'cd' to make sure the working directory is correct)

Thanks in advance.
 
Why are you using the tilde in front of /app?

You don't need to cd to the path, just use it like this:
Code:
@reboot /app/forever_start.sh

Or if the script searches for files in the directory it starts from you could try like this:
Code:
@reboot cd /app && ./forever_start.sh
without the tilde as you can see....
or
Code:
@reboot cd /app && /app/forever_start.sh
 
The tilde is to provide the home directory of the user running the script. So, if you reboot... who's is the user running the script? This can be 'root' (most likely) or some other user, but to make sure, you might replace the ~ with e.g. /root/ of wherever your script is located.

The second thing you might remember is that the evironment when booting might be completely different. If you're script doesn't do what it should do, check if you use full paths in your script:
"/usr/local/bin/program" vs. "./program" of "program".

Still no luck? Debug it. Use something like '/usr/bin/logger "`/usr/bin/date`: i am here!" in your script to log stuff in /var/log/messages

Hope this helps!
 
I don't think he means to run this in a users home directory.

If directadmin is used and the script would be started in a users /home directory, you can allow users to run scripts and run the script from his home directory. Which is a lot easier.
I've got it the same for a ts3 server which runs as a user from a users home directory like this:
Code:
@reboot /home/user/ts3check.sh
This also prevents the need to "cd" to the users directory.
 
Back
Top