My setup involves running python and node scripts as cron jobs on EC2. Interestingly, the python scripts are executing without any issues, but the node scripts seem to be failing. When I manually activate the node scripts from the command line, they work perfectly fine. The node script in question is a basic one that checks if it's a holiday today and stores the boolean answer in a file called isHoliday.csv.
Here's what I have tried so far:
- Added the cron job using: crontab -e (the last entry in this screenshot) https://i.sstatic.net/WyBWe.png
- Added the cron job using: sudo crontab -e https://i.sstatic.net/zCFwh.png
- Created a cron.d file, entered the cron details, changed the permissions to 0644, and added it using: sudo crontab -e; as shown below. Contents of cron.d: https://i.sstatic.net/iYmLQ.png
I noticed that the log file is named holiday_script.log when using sudo cron and holiday.log when using the cron.d file, but neither log file has been generated.
- Switched relative paths to absolute paths. (But I suspect this might still be the root cause.)
Here is the code snippet from the holiday.js file:
// Check if it is a holiday, true/false
var holidayChecker = require('usa-holidays');
var date = new Date();
var holidayObj = holidayChecker.make(date);
var isHoliday = !holidayObj.isBusinessDay();
// Save the result in a file for python scripts to read
var fs = require('fs');
fs.writeFile("/home/ec2-user/stack/isHoliday.csv", isHoliday, function(err) {
if(err) {
return console.log(err);
}
});