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 8864941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:22:47+00:00 2026-06-14T16:22:47+00:00

I have a linux shell script that when run from command line works perfectly

  • 0

I have a linux shell script that when run from command line works perfectly but when scheduled to run via crontab, it does not give desired results.

The script is quite simple, it checks to see if mysql-proxy is running or not by checking if its pid is found using the pidof command. If found to be off, it attempts to start the proxy.

# Check if mysql proxy is off
# if found off, attempt to start it

if pidof mysql-proxy 
then
    echo "Proxy running."
else
    echo "Proxy off ... attempting to restart"
    /usr/local/mysql-proxy/bin/mysql-proxy -P 172.20.10.196:3306 --daemon --proxy-backend-addresses=172.20.10.194 --proxy-backend-addresses=172.20.10.195

    if pidof mysql-proxy
    then
        echo "Proxy started"
    else
        echo "Proxy restar failed"
    fi
fi
echo "==============================================="

The script is saved in a file check-sql-proxy.sh and has permissions set to 777. When I run the script from command line (sh check-sql-proxy.sh) it gives the desired output.

4066
Proxy running.
===============================================

The script is also scheduled to run every 5 minutes in crontab as

*/5 * * * * bash /root/auto-restart-mysql-proxy.sh > /dev/sql-proxy-restart-log.log

However, when I see the sql-proxy-restart-log.log file it contains the output:

Proxy off ... attempting to restart
Proxy restar failed
===============================================

It seems that pidof command fails to return the pid of the running application which brings the flow of script in else condition.

I am unable to figure out how to resolve this since when I run the script manually, it works fine.

Can anyone help what I am missing with regards to permissions or settings?

Thanks in advance.
Mudasser

  • 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-06-14T16:22:48+00:00Added an answer on June 14, 2026 at 4:22 pm

    Check that the shell is what you think it is (usually /bin/sh, not bash)

    Also check that PATH environment variable. Usually, for cron jobs it is a good practice to fully qualify all paths to binaries, e.g.

    #!/bin/bash
    # Check if mysql proxy is off
    # if found off, attempt to start it
    
    if /bin/pidof mysql-proxy 
    

    etc.

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

Sidebar

Related Questions

I have a shell script, which is run under a opensuse linux, that starts
I have a script that runs from a newly created shell. OS is Red
I have a shell script that works on Ubuntu and provides me an output
I have a simple Linux shell script that parses a file generated in windows
I need an Eclipse Plugin run shell scripts under Linux. I have a beautiful
I am trying to implement a linux shell that supports piping. I have already
I have debian linux. I've created from user crontab -e this text: 0 *
I have a python script that I run to populate my database. I usually
I have the following line in a shell script: if [ -f /etc/init.d/tomcat6 &&
I have a Java console application that is launched from a batch script in

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.