Hello together,
Using screen (http://nerdierthanthou.nfshost.com/2004 ... howto.html) I start several PHP scripts in different screens, which run endlessly.
Sometimes a script crashes. Such scripts should automatically be restarted.
One can check if a specific script is still running, by using 'ps -aux' , displaying running process. If the script is not running anymore, the shell script sould restart the script automatically. How can I check if a specific script is still running and if not, restart the script with /opt/lampp/bin/php my_script.php?
Since I'm a newbie in shell scripting, I would appreciate any helpful, practical suggestions and examples. I don't know where to start off...
Thanks,
visionmaster
Shell script and ps aux
Moderator: General Moderators
-
visionmaster
- Forum Contributor
- Posts: 139
- Joined: Wed Jul 14, 2004 4:06 am
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Don't write your shell scripts in BASH... you already have PHP under your belt so use that 
CHMOD the file to 0770 and it should be executable like a bash script 
Code: Select all
#!/usr/bin/php
<?php
$command = '/usr/bin/php file.php';
$data = `ps aux | grep $command`;
if (empty($data)) echo "Process dead\n";
else echo "It's alive!!!";
?>