Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3634928
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:50:24+00:00 2026-05-19T00:50:24+00:00

I would like to have a shell scipt that runs infinitely and keeps checking

  • 0

I would like to have a shell scipt that runs infinitely and keeps checking status of a php script (say my.php) and restarts it if the script has terminated somehow. I have the idea to go for –

ps -aux | grep "my.php"

and then use the result of this to check the status and do accordingly. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:50:25+00:00Added an answer on May 19, 2026 at 12:50 am

    You can simply say:

    ps -aux | grep -q "my.php" || php -f my.php
    

    The way it works is that grep -q will not output anything but will return an “OK” exit code if it found something. when it returns a “NOT OK” exit code, the part after the || (“or”) gets executed (because of boolean short-circuit evaluation – look it up).

    You also need to make sure that:

    1. you run the new script in the background and detach it from your console so that your script can keep monitoring

    2. when you run ps | grep sometimes ps also lists your grep and then the grep “greps itself”, so you have to filter that out.

    It should look something like this:

    while true
        ps -aux | grep -v grep | grep -q "my.php" || ( nohup php -f "my.php" & )
        sleep 1
    done
    

    or some-such..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a shell script that copies some logs from a
I have a shell script that I would like to run at the end
I have a Korn shell script that I would like to change a variable
I would like to introduce multithreading feature in my shell script. I have a
I have a shell script that calls a java jar file and runs an
I have a Bash shell script that invokes a number of commands. I would
#!/bin/bash for((i=1;i <=10;i++)) do php /var/www/get.php done I have the above shell script that
I have a shell script that runs on my server every day. It does
I have an application that I'm creating and would like to run a shell
When I'm running eshell (or shell) in emacs, I would like to have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.