Start/Stop apache using shell script
I am trying to start/stop apache 2.2, 开发者_Python百科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.
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.
精彩评论