EC2 experiencing issues with Node cron execution

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:

  1. Added the cron job using: crontab -e (the last entry in this screenshot) https://i.sstatic.net/WyBWe.png
  2. Added the cron job using: sudo crontab -e https://i.sstatic.net/zCFwh.png
  3. 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.

  1. 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);
    }
});

https://i.sstatic.net/w5pql.png

Answer №1

While I may not have the exact solution, one way to troubleshoot is by checking your cron logs in a different directory. After logging into EC2, try moving up two directories with the command cd ... Next, switch user to sudo using sudo su and then navigate to the var/log folder. Look for a file named "cron" which should be constantly filling with data due to your crons setup as *****. Use the command tail -f cron to view cron executions in real time.

Additionally, check the "mail" folder and use the less command to read any mail notices that might provide further clues. Scroll down using the down-arrow key.

While this information may not solve your issue entirely, it can definitely help point you in the right direction.

Answer №2

For those seeking to execute JS/TS code at specific intervals without the hassle of cron-jobs or servers, explore options such as

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When using nativescript-vue to navigate to a Vue page, the props are cached for later

A couple of days back, I managed to resolve the issue I was facing with navigating through Vue pages. However, after fixing that problem, I made an error by mistakenly attempting to pass an incorrect key value to the Vue page I was redirecting to. When th ...

Tips for building a live React app!

I'm looking to develop a real-time news application that displays a list of countries with the latest news next to each country name, automatically updating as new information is added to the API. For instance, I have an endpoint like this: (for Aust ...

Proper method to refresh a blog post that has undergone revisions

Good evening, everyone. I almost have my site ready for testing, just one last piece to go! I'm struggling with the correct way to do this. Currently, I am working on a blogging CMS of sorts. I display blog posts in individual divs, each containing ...

Getting the Value from a Promise into a Variable in a React Component

I am currently immersed in a React project where I am utilizing the Axios library to retrieve data from an API and store it in a variable. After scouring the internet, it seems that the only method available is through Promise.then(), but this approach si ...

PHP-powered Countdown Timer for triggering a button's action

Hey everyone, I could use some assistance. Here's my situation - I have a database table with a column called "created_time" that stores the current system time in HH:MM AM/PM format. I want to have a button on one of my PHP pages named "Start Exam" t ...

Conceal a row depending on the value in a specific column

After reviewing the data in the table provided: +-----------------------+-----------------+---------------+ | 212 | fred | red | +-----------------------+-----------------+---------------+ | 230 ...

Transforming a jsonObject into a JavaScript array

I am working with a JSON object and I need to extract data from it to create an array. Here is an example of the desired array: ['city 1','city 2','city ..'] Below is the JSON output: {"\u0000*\u0000_data":[{"id": ...

Add a close event to a list item in JQuery before

When I click on "+ List Item" or press enter in the input box, I want to add a new list item with a checkbox, input box, and a close button. The functionality should be similar to Google Keep's checked item event working in notes. Currently, the code ...

The function or method 'uploadify' is not compatible with this object

I am encountering an issue while attempting to utilize the jQuery uploadify functions within my aspx page. Upon the page load and execution of $(document).ready, an exception is triggered. It appears that, for some unknown reason, the FileUpload1 control i ...

A recursive function that utilizes a for loop is implemented

I am encountering a critical issue with a recursive function. Here is the code snippet of my recursive function: iterateJson(data, jsonData, returnedSelf) { var obj = { "name": data.groupName, "size": 4350, "type": data.groupType }; if ...

The Firebase storage percentChanges() method is throwing a NaN error

I want to create a Firebase storage service using an Angular client to handle user profile image uploads. This service should return two observables: uploadProgress$ and downloadUrl$. The uploadProgress$ observable will store the value from percentChanges ...

What is the best way to set the state to false upon unmounting a component in react?

Currently, I am controlling the state of a dialog using context. Initially, the isOpen state is set to false. When the add button is clicked, the state isOpen becomes true and clicking the cancel button will revert it back to false. If the user does not c ...

Is your React conditional rendering malfunctioning due to state issues?

I am attempting to create a component that will only be displayed after clicking on a search button. Below is the current code that I have: Update After making some changes, I am now encountering this error: Error: ERROR in /home/holborn/Documents/Work ...

Troubleshooting: jQuery animation for background-color doesn't function in Internet Explorer

I've been working on a website and I'm trying to create a navigation bar similar to the one found at . My goal is to have the navbar transition from transparent to a colored background as the user scrolls down the page. For this project, I am ut ...

The issue with Mongoose not properly dropping the database and closing the connection is causing unexpected behavior in Mocha tests

I encountered an issue with my tests - one passed and the other failed due to a problem with the Schema being compiled again. Error: Cannot overwrite CheckStaging model once compiled. The first test that passed: var mongoose = require('mongoose& ...

The message from the Discord bot is not displayed in an embedded format

When using the code below: message.reply('some reply', { embed: { color: 3447003, description: "A very simple Embed!" } }); } the response from my bot will appear as a regular messa ...

Utilizing the {{value}} parameter within the JavaScript block of the thinger.io HTML gadget

When creating an HTML widget with JavaScript code on the thinger.io Dashboard, you can easily include data from the "thing" by using {{value}} within HTML tags. However, incorporating this data into a JavaScript block poses a challenge. Example of a Pure ...

Conditional compilation in Laravel Mix allows for specific code blocks to be

I'm currently working on a Laravel project and I need to introduce some conditional statements. Within the root folder of the project, there's a file called module_statuses.json which contains JSON variables like this: { "Module1": true, ...

What is the best way to determine the duration it takes for a perspective camera to move from one position to another

As my perspective camera moves along a spline curve, I need to determine the amount of time it has traveled. I have already calculated the total distance covered. What should be my next step? ...

What could be causing AJAX to consistently return identical data to the callback function when distinct objects are supplied as arguments?

I am attempting to make two separate calls to an MVC controller. The first call returns a series of data, while the second call returns a partial view. When I check in Firebug, both calls show "success" status. I am trying to utilize a callback function t ...