Reputation: 1
I was very hesitant to post here since this question have been popped out a ton, but I've tried pretty much everything I've found on the internet in last 2 days. I am on my first week using Linux and its been a wild ride. (Ubuntu 20.04 LTS)
So I made node app which opens browser -> logins to our company webapp and writes down my work hours automatically, I want to run it on computer reboot since I mark my hours when I get home. This way I dont forget to mark them. (note: I have also tried running it on every minute, or the next coming minute just to be sure its not about @reboot command)
These are some of the different options I've tried. Cant really remember all since I've been trying, I belive over 100 different variants now. Also on the codes below, I've also tried with either full paths or just ex. bin/node etc.
@reboot cd /home/sepi/Documents/MyProjects/eas_app && /usr/local/bin/node index.js
@reboot usr/local/bin/node /home/sepi/Documents/MyProjects/eas_app/index.js
@reboot /bin/node /home/sepi/Documents/MyProjects/eas_app/index.js
which node gives: /usr/local/bin/node
Upvotes: 0
Views: 266
Reputation: 747
First check where is your node binary by
$ whereis node
and use that path only in cronjob.
To resolve any cronjob first thing you need to do is to redirect stdout and stderr in a log file.
@reboot /bin/node /home/sepi/Documents/MyProjects/eas_app/index.js > out.log 2>&1
This way you will understand if is there any library or path issue.
If you are still facing the issue then just add the below lines in your crontab
SHELL=/bin/bash
BASH_ENV="/home/user/.bashrc"
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
In BASH_ENV instead of user add your username, check by whoami
Note: SHELL and PATH entry can be found by echo $SHELL
and echo $PATH
respectively.
Also first add time base cron to test if it is working then add cronjob for reboot scenarios.
Upvotes: 1