Nodejs app not working with crontab #reboot - node.js

T'm trying to run a nodejs program after system reboot, I'm using crontab #reboot to do this but it did not work.
Here is my config steps, any idea what's wrong?
I'm using aws linux, and installed nodejs by nvm;
which node
/root/.nvm/versions/node/v8.9.3/bin/node
my test.js located
/home/ec2-user/spider/logger.js
this works fine
/root/.nvm/versions/node/v8.9.3/bin/node /home/ec2-user/spider/logger.js
this also works fine
#reboot echo "hi" > /home/reboot.txt 2>&1
crontab -e
#reboot /root/.nvm/versions/node/v7.1.0/bin/node /home/user/test.js
reboot, test.js never gets run
Also tried :
* * * * * /root/.nvm/versions/node/v8.9.3/bin/node /home/ec2-user/spider/logger.js >> /home/crontab.log 2>&1
* * * * * echo $(date '+%Y %b %d %H:%M') >> /home/reboot.txt 2>&1
* * * * * echo "hi" >> /home/hi.txt 2>&1
Only last one worked.

The crontab syntax composed of two parts, datetime to execute & command to be executed. In this case, you command is /root/.nvm/versions/node/v7.1.0/bin/node /home/user/test.js
* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)

Related

Impossible to run .sh Script with crontab

i am trying to schedule my script.sh script to run every day from monday to friday at 9:35 am. When I run my script with ./ directly in the terminal everything works fine. But when I tried to run in the crontab -e nothing worked.
Here is the list of what I tried:
- * * * * * root /bin/script.sh
- * * * * * root sh /bin/script.sh
- * * * * * root bash /bin/script.sh
- * * * * * root / bin / sh /bin/script.sh
- * * * * * /bin/script.sh
- * * * * * sh /bin/script.sh
- * * * * * bash /bin/script.sh
- * * * * * / bin / sh /bin/script.sh
I put an execution every minute just for the test.
Otherwise the final command will be something like this:
- 35 9 * * 1-5 /bin/script.sh
I must have forgotten an important step or something.
Of course I restartcron with each modification with:
- service cron restart
That should work
* * * * * /bin/bash /bin/script.sh
You can also add a shebang in the beginning of your script
#!/bin/bash
... your script here ...
This will let you execute the script directly by calling it with /bin/script.sh
The system will know that he need to start bash to execute it
You will need to get execution access right
chmod +x /bin/script.sh
This will give execution rights to anyone, check chmod man if you want to give execution access to only owner
The cron will be just like that
* * * * * /bin/script.sh
Keep in mind you will not get any output with a cron, you can still redirect stdout to a log file
* * * * * /bin/script.sh >> /var/log/myscript.log
If you use crontab -e as root, you don't need to use sudo or anything like that

run multiple task in crontab in the same time without delay

I have to run task which take time 3 or 5 minut
How to run multiple task in crontab -in same time ?
crontab -e
0 13 * * * /etc/rip_first_radio.sh
0 13 * * * /etc/rip_second_radio.sh
0 13 * * * /etc/rip_third_radio.sh
0 13 * * * /etc/rip_fourth_radio.sh
your crontab config is correct. But you can add add all into one script and run also.
vi main.sh
./etc/rip_first_radio.sh &
./etc/rip_second_radio.sh &
./etc/rip_third_radio.sh &
./etc/rip_fourth_radio.sh &
and add main.sh to cron.
0 13 * * * ./main.sh

My VPS restarting every hour

Hello my server is restarting every hour, where the problem ?
Centos 6.6 with WHM/Cpanel
This my cronjob
root#server [/etc/cron.d]# crontab -l
0 6 * * * /usr/local/cpanel/scripts/exim_tidydb > /dev/null 2>&1
30 5 * * * /usr/local/cpanel/scripts/optimize_eximstats > /dev/null 2>&1
2,58 * * * * /usr/local/bandmin/bandmin
0 0 * * * /usr/local/bandmin/ipaddrmap
18 23 * * * /usr/local/cpanel/scripts/upcp --cron
0 1 * * * /usr/local/cpanel/scripts/cpbackup
0 2 * * * /usr/local/cpanel/bin/backup
35 * * * * /usr/bin/test -x /usr/local/cpanel/bin/tail-check && /usr/local/cpanel/bin/tail-check
45 */4 * * * /usr/bin/test -x /usr/local/cpanel/scripts/update_mailman_cache && /usr/local/cpanel/scripts/update_mailman_cache
30 */4 * * * /usr/bin/test -x /usr/local/cpanel/scripts/update_db_cache && /usr/local/cpanel/scripts/update_db_cache
30 */2 * * * /usr/local/cpanel/bin/mysqluserstore >/dev/null 2>&1
15 */2 * * * /usr/local/cpanel/bin/dbindex >/dev/null 2>&1
15 */6 * * * /usr/local/cpanel/scripts/autorepair recoverymgmt >/dev/null 2>&1
*/5 * * * * /usr/local/cpanel/bin/dcpumon >/dev/null 2>&1
46 0 * * * /usr/local/cpanel/whostmgr/docroot/cgi/cpaddons_report.pl --notify
7,22,37,52 * * * * /usr/local/cpanel/whostmgr/bin/dnsqueue > /dev/null 2>&1
42 4 * * * /usr/local/cpanel/3rdparty/bin/freshclam --quiet --no-warnings
Just looking at your cron jobs I can see that this job runs every hour, so that is a good place to start looking:
35 * * * * /usr/bin/test -x /usr/local/cpanel/bin/tail-check && /usr/local/cpanel/bin/tail-check
Also, this job runs twice an hour, but they happen so close together that it might appear to occur only once. Check it out next:
2,58 * * * * /usr/local/bandmin/bandmin
If you can, I would just comment out these 2 jobs for a few hours and see if that solves your problem. If it does then you know one of these is causing the reboot.

How to create a cronjob that runs every 5 minutes from 8:30 AM to 9:30 PM?

I am trying to run a cron job every 5 minutes from 8:30 AM to 9:30 PM. I've been searching around the web and here is what I came up with:
30,35,40,45,50,55 8 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
*/5 9-21 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
5,10,15,20,25,30 22 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
I have looked at cron job generators but they do not seem to address the requirement to start/end on the half-hour. Does anyone have a better or more concise solution?
30-59/5 8 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
*/5 9-20 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
0-30/5 21 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
should also work, and easier to read.
30-59/5 8-20 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
00-25/5 9-21 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
would serve the purpose.

Cronjob every x hours between 23-16 not working

Partly using stackoverflow search I figured out how to run my cronjob every 3 hours but not between 23h-16h. That means a pause between 16h today untill 23h today. So the cronjob should start running every 3 hours at 23h and stop at 16h, then start again at 23h.
This is the result:
0 23-16/3 * * * /usr/local/bin/flexget -c /media/usb/Downloads/flexget/config.yml --cron
Now my question: Why is this not working? It does not run at all :(
I also tried:
* 23-16/3 * * * /usr/local/bin/flexget -c /media/usb/Downloads/flexget/config.yml --cron
(not sure what the difference is with 0 or with * for the minutes, rounded hours or not?)
This DOES work:
0 */3 * * * /usr/local/bin/flexget -c /media/usb/Downloads/flexget/config.yml --cron
But then it just runs every 3 hours every day, without pause between 16-23.
You can always list the hours explicitly.
0 2,5,8,11,14,23 * * * /usr/local/bin/flexget -c /media/usb/Downloads/flexget/config.yml --cron
Note this is not the same as with replacing 0 minutes with *, like:
* 2,5,8,11,14,23 * * * /usr/local/bin/flexget -c /media/usb/Downloads/flexget/config.yml --cron
The latter starts on every minute on the hours specified, i.e. 2:00, 2:01, 2:02, ..., 2:59, 5:00, 5:01, ... 5:59, ...

Resources