A simple custom php is enough to achieve. No need to be confused with shell script.
suggests that you want to run php / home / mypath / example.php if you don't run
Then use the following custom php script to do the same job.
create the following /home/mypath/forever.php
<?php $cmd = $argv[1]; $grep = "ps -ef | grep '".$cmd."'"; exec($grep,$out); if(count($out)<5){ $cmd .= ' > /dev/null 2>/dev/null &'; exec($cmd,$out); print_r($out); } ?>
Then in your cron add the following
* * * * * php /home/mypath/forever.php 'php /home/mypath/example.php'
lingeshram Apr 10 '16 at 17:42 on 2016-04-10 17:42
source share