Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 3721  / 2 Years ago, sat, april 16, 2022, 6:07:03

I have created a Cron job to run a script that checks if a process is running, in case it does it just print that the process is running, if not it prints out the process is not running and restart the process:


#!/bin/sh

SERVICE="start_server.py"
if ps -ef | grep "$SERVICE" | grep -v grep >/dev/null
then
echo "start_server.py is running"
else
echo "start_server.py stopped"
python2.7 start_server.py &
fi

As user Ubuntu I created the following cron job by running - crontab -e


* * * * * /home/ubuntu/mislaka/check_process.sh 2>&1 /home/ubuntu/mislaka/script_log.log

For some reason, it is not working or writing the output to the log file.


Tried restarting cron service, tried creating the cron job as root, changed all the permission and the user who is running the script yet nothing is working.


The script if I run it by itself works as expected.


Ubuntu Version:


No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal

Thanks in advance


More From » 20.04

 Answers
0

The issue was that I needed to change my script and edit the cron job to run the correct script and added full path to the script.


[#1368] Sunday, April 17, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eryeath

Total Points: 122
Total Questions: 121
Total Answers: 112

Location: Saint Helena
Member since Fri, Aug 26, 2022
2 Years ago
;