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

  • Home
  • SEARCH
  • 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 6046937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:17:47+00:00 2026-05-23T07:17:47+00:00

shell script: #!/bin/sh services=( httpd named proftpd mysqld dovecot postfix webmin) for service in

  • 0

shell script:

#!/bin/sh
services=( httpd named proftpd mysqld dovecot postfix webmin)

for service in ${services[@]}
do

if ps ax | grep -v grep | grep $service > /dev/null
then
    echo "$service service running, everything is fine"     
else
    echo "$service is not running"
    service $service start
fi

done 

file executable, running from root user

command:

bash /etc/mycron/checkServices.sh

tried sh and just /etc/mycron/checkServices.sh

doesn’t run

  • 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-23T07:17:48+00:00Added an answer on May 23, 2026 at 7:17 am
    #!/bin/sh
    services=( httpd named proftpd mysqld dovecot postfix webmin)
    
    for service in ${services[@]}; do
        if ps ax | grep -v grep | grep $service > /dev/null; then
            echo "$service service running, everything is fine";
        else
            echo "$service is not running";
            service $service start;
        fi;
    done;
    

    Works fine here… maybe you want to add after #!/bin/sh PATH="/bin:/sbin:/usr/bin:/usr/sbin:/opt/usr/bin:/opt/usr/sbin:/usr/local/bin:/usr/local/sbin"

    You could also do chmod 775 /etc/mycron/checkServices.sh to make it executable, which is needed for cron. Then you would also not need to call bash /etc/mycron/checkServices.sh and can just call /etc/mycron/checkServices.sh the #!/bin/sh tells the executable loader to load the file with /bin/sh if you invoke bash /etc/mycron/checkServices.sh you will start bash which on his turn would start /bin/sh to finally execute your script.

    Since the for loop in bash / sh uses the IFS variable ($IFS) as delimiter, you could also make the line services=(httpd named proftpd mysqld dovecot postfix webmin) as services="httpd named proftpd mysqld dovecot postfix webmin" since this is more general

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

Sidebar

Related Questions

Suppose a shell script (/bin/sh or /bin/bash) contained several commands. How can I cleanly
I have a bash shell script which has the line: g=$(/bin/printf ${i}) when ${i}
I have this shell script #!/bin/sh ############################################################# # Example startup script for the SecureTrading
shell>/bin/date -d 091029 20:18:02 +%s 1256827682 Similarly I created shell script: #My.sh myDate=`date +'%y%m%d_%H%M%S'`
I have a tiny shell script that writes to a serial device: #!/usr/bin/ruby require
I have a shell script file (run.sh) that contains the following: #!/bin/bash %JAVA_HOME%/bin/java -jar
I've a cgi shell script like this #!/bin/sh # show the page echo Content-type:
Let's say I've got a shell script called print_error.sh looking like this: #!/usr/bin/bash echo
I have a shell script ( /home/user/send_report.sh ) that runs my rake task: cd
I have shell scripting knowledge. I have written a small shell script which will

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.