LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   startup script not working (https://www.linuxquestions.org/questions/linux-newbie-8/startup-script-not-working-756804/)

davidstvz 09-21-2009 12:50 PM

startup script not working
 
I made a startup script to automatically start MySQL Daemon on startup. However, for some reason it's not working on a restart (but if I call it manually with the "start" option it works).

I used "who -r" to confirm my default run level is 5, and I put the script in /etc/init.d/mysqlds and I link to it from rc5.d with the name: S24mysqlds --> ../mysqlds

The only odd thing I can note is that when I run the script manually, it doesn't return to the command prompt until I hit the enter key. Any ideas why this isn't bringing up the mysql server on the restart?

Here's the script (my password replaced with asterisks). Maybe the problem is permissions. I set it to -rwx------ so the password is not readable, but I would have thought booting occurs with root privileges.

Code:

#!/bin/sh
#

case ${1} in
    stop*)
        /usr/bin/mysqladmin -u root --password=******** shutdown
    ;;
esac

case ${1} in
    start*)
        /usr/bin/mysqld_safe --user=mysql --log &
    ;;
esac


forrestt 09-21-2009 01:06 PM

You only need one case statement. I don't think you want '*' after each option (I've never seen this). You also probably want to put double quotes around your ${1}. Also, why are you writing a script when one comes w/ mysql?

Try:
Code:

#!/bin/sh

case "${1}" in
    stop)
        /usr/bin/mysqladmin -u root --password=******** shutdown
        ;;
    start)
        /usr/bin/mysqld_safe --user=mysql --log &
        ;;
    *)
        echo $"Usage: $0 {start|stop}"
        exit 1
esac

If this is an exercise in coding, I hope the above helps. If this is truly an attempt to automatically start/stop MySQL, then you really should use the script they provide.

HTH

Forrest

p.s. I didn't mean to imply that the '*' in a case statement wasn't valid, only that you don't need to match on start* and stop*.

davidstvz 09-21-2009 01:17 PM

Not an assignment, this really is a script I threw together real quick by copying another script and editing it a bit. I was kind of in a rush.

I'll try the official script when I have a chance, thanks for the link.

catkin 09-21-2009 01:23 PM

In case it's any help, the { and } in "${1}" are unnecessary and there's a typo in
Code:

echo $"Usage: $0 {start|stop}"
where the $ in front of the doubly quoted string has sneaked in unwanted.

forrestt 09-21-2009 01:35 PM

The echo line was copied directly from the mysql.server script on my system (and then the other options were then removed), but the line works on my system even with the $ (although I don't know if it was put there on purpose or not. Also, I know the { and } are unnecessary, but they follow the style that the OP was using for variable referencing (and is my preference as well, although I didn't change the $0 to ${0} in the copied line).

Forrest

p.s. on further examination (I got curious), I've noticed that most of the "Usage" lines in my /etc/init.d scripts are 'echo $"Usage:...'.

catkin 09-21-2009 02:02 PM

Quote:

Originally Posted by forrestt (Post 3691963)
p.s. on further examination (I got curious), I've noticed that most of the "Usage" lines in my /etc/init.d scripts are 'echo $"Usage:...'.

Thanks for the info :) Just looked it up and found it's a locale feature: "Bash supports the $"..." quoting syntax to do locale-specific translation of the characters between the double quotes.". Always something new to learn about bash!

forrestt 09-21-2009 02:07 PM

Glad you pointed that out cause I've been hitting Google pretty hard w/ all kinds of 'bash echo $""' type queries (along w/ pounding my head on my desk).

Forrest

catkin 09-21-2009 02:29 PM

Quote:

Originally Posted by forrestt (Post 3692000)
Glad you pointed that out cause I've been hitting Google pretty hard w/ all kinds of 'bash echo $""' type queries

Yeah -- that's a hard thing to Google for! I started out guessing it might be a sh backwards compatibility thing so checked the bash reference for bash/sh differences and got lucky!


All times are GMT -5. The time now is 05:16 AM.