LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-21-2009, 12:50 PM   #1
davidstvz
Member
 
Registered: Jun 2008
Posts: 405

Rep: Reputation: 31
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

Last edited by davidstvz; 09-21-2009 at 12:52 PM.
 
Old 09-21-2009, 01:06 PM   #2
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
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*.

Last edited by forrestt; 09-21-2009 at 01:13 PM. Reason: added p.s.
 
Old 09-21-2009, 01:17 PM   #3
davidstvz
Member
 
Registered: Jun 2008
Posts: 405

Original Poster
Rep: Reputation: 31
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.
 
Old 09-21-2009, 01:23 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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.
 
Old 09-21-2009, 01:35 PM   #5
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
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:...'.

Last edited by forrestt; 09-21-2009 at 01:46 PM. Reason: added the p.s.
 
Old 09-21-2009, 02:02 PM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by forrestt View Post
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!
 
Old 09-21-2009, 02:07 PM   #7
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
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
 
Old 09-21-2009, 02:29 PM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by forrestt View Post
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!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
startup script not working in RHEL 4 shipon_97 Linux - Enterprise 3 08-09-2007 01:13 PM
Startup script not working in rc.local crackerB Linux - Software 9 10-09-2006 07:55 AM
'cannot stat' script in /etc/rc.d/, try to run script at startup quintan Linux - Software 1 11-21-2005 02:53 AM
How to call a script from a system startup script? jonatito Linux - Newbie 7 11-11-2005 09:40 PM
TOMCAT init script not working on startup -- tomcat 4.x / Mandrake Linux 8.0 jmartinph Mandriva 0 03-08-2004 01:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration