0

I am trying to start/stop apache 2.2, using shell script. At present I am using: /usr/local/apache/bin/apachectl start /usr/local/apache/bin/apachectl stop

If there is a way to start it: ./StartApache.sh start

Thanks in advance.

4
  • What OS? and why aren't you using /etc/init.d/ or some such Commented Sep 26, 2011 at 6:48
  • 1
    Will you be using ./StopApache.sh stop to stop it? Commented Sep 26, 2011 at 6:50
  • Sorry, it would be ./Apache start/stop. Commented Sep 26, 2011 at 6:52
  • Why would you want to use a script in the current directory instead of the control program in the public directory? Commented Sep 26, 2011 at 6:53

1 Answer 1

4

Why not use the official way - the apachectl script? You can write your own script that invokes the official script, but why bother? And you certainly don't want it in your current directory - you have lots of directories, don't you? You might add your script to a directory on your PATH (such as $HOME/bin, assuming you have that directory and it appears on your PATH); you might simply add a symbolic link to a directory on your PATH that points at the official script.

If you must do it, then:

cd $HOME/bin &&
ln -s /usr/local/apache/bin/apachectl ./Apache

Now you can do:

./Apache start
./Apache stop
./Apache restart

when you're in your $HOME/bin directory, and (more usually) just:

Apache start
Apache stop
Apache restart

without any path specified, so the shell finds the script for you. Of course, you could also simply add /usr/local/apache/bin to your PATH and use apachectl directly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.