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