Reputation: 77
I have a cronjob that is running every hour and there is a loop in it that loop every seconds.
This is a sample of the cron file which is named processor.php
$i=1
while($i<3600){
sleep(1);
$i++;
}
I found out my webserver was down for half hour last night. Now I am going to make a program on different server, if see my server is not alive. connect thru ssh to server then restarts httpd and mysqld.
But I am worry about the cronjobes so I want to know if there is a command to show after restarting processor.php is running or not. if not , try to run.
Now my question is how can I see a processor.php is working on background or not. I see this in htop but I need something like ps command.
Thank you in advance
Upvotes: 1
Views: 1066
Reputation: 21
Do a bash script like this, and add it to your cron.
#!/bin/bash
ps -ef|grep phpscript.php |grep -v grep
if [ $? = "0" ]
then
echo "Running"
else
echo "Restart"
/path/to/restart/phpscript.php
fi
Upvotes: 2