Forums

Shell script not executing from Cron

Hi All, Greetings of the day!! I have made a shell script to check a application service to be running and if found not running, then it should start the service. I did run the script manually on the server however when I schedule it to ru...

Hi All,

Greetings of the day!!
I have made a shell script to check a application service to be running and if found not running, then it should start the service. I did run the script manually on the server however when I schedule it to run every 5 minutes through cron, it does not. Could sone please check and suggest if I am missing something.

Script used:-

#!/bin/bash

# Define the name of the service
SERVICE_NAME="trcbroker.service"

# Check if the service is running
if systemctl is-active --quiet $SERVICE_NAME ; then
    echo "$SERVICE_NAME is running."
else
    # Attempt to start the service
    systemctl start $SERVICE_NAME
    # Check if the service started successfully
    if systemctl is-active --quiet $SERVICE_NAME ; then
        echo "$SERVICE_NAME started successfully."
    else
        echo "Failed to start $SERVICE_NAME."
    fi
fi

In cron I am using the below line to make the script run which I have stored in /tmp with 755 permissions:-

*/5 * * * * /path/to/monitor_trcbroker.sh

Regards,
VT

2 posts - 2 participants

Read full topic