kitimenpolku
kitimenpolku

Reputation: 2604

Cannot make a cronjob get the status of a service

I'm using Upstart to run a couple of services when the systems reboots. Those services should always be running. I have noticed that some of then crashed eventually, so I'm trying (without success) to create a watchdog script.

This script will check the status of the service. If the service is down, then it should start the service and send me an email about the issue. The email script is in php and is okay.

The problem with the watchdog bash script is that I'm just able to execute the script and read the status of the service if I launch the script manually.When using a cronjob for executing the script I get an "empty status" output.

I'll show you the script:

#!/bin/bash
# Check the service
status=$(status SERVICE | awk '{print $2}')
echo "Status of the SERVICE: $status"

When I execute it manually I get:

Status of the SERVICE: stop/waiting

And If execute it with a cronjob I get:

Status of the SERVICE:

As you see I'm not getting any output when executing the script with a cronjob. In short, the cronjob is running but without providing me with the status of the service.

Hope your X-vision can see the error that I'm not able.

BR,

albertof

Upvotes: 3

Views: 314

Answers (1)

Eric
Eric

Reputation: 3172

The difference is usually environment variables. Likely PATH. Run

which status

To show what executable it's running, and then put that full path into the cron invocation.

Upvotes: 1

Related Questions