Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I made 2 .sh scripts to start and stop Xampp server. I'd like to merge them in a single launcher to obtain something like a ON/OFF button, so that if Xampp has already been started it would stop, but I don't know how to do that.

The code I have in my script is this:


sudo /opt/lampp/lampp start;
echo "Starts Xampp server";

Can someone help me?

P.S. I read this answer but it doesn't help...why did Oli said "But I'll leave this up to you"? :P

share|improve this question
up vote 1 down vote accepted

I do not currently have a xampp server setup, BUT, it should be something like this :

 if [ $(ps aux | grep ###XAMPP PROCESS NAME### | wc -l) -gt 0;then
      echo "Process is running, stopping"
      echo "Process is not running, starting"

like I said, I do not use xampp, so I'm not exactly sure what the process is called, or the commands to start and stop it, but this will work if you edit it with the process name and start/stop commands. The other guy had it right, just didn't simplify it with "command to stop/start"

EDIT : syntax error :)

share|improve this answer

I don't especially about Xampp server suite but you could write something like the following, it does a ps aux (show all processes) and greps for the process you want to have running, then counts the results. grep [p]rocess is used to exclude the grep process itself, you could to the same with grep process | grep -v grep but this is a shorter version of it.

if [ $(ps aux | grep [a]pache | wc -l) -gt 0 ]; then
     echo "Process is running"
     echo "Process is not running"

Hope this is waat you are looking for.

share|improve this answer
I don't seems to be more complex than I expected. I edited my question and added the code I have in my .sh file. And I can't understand if the code you suggested can actually start/stop the process (and this is what I need), or if it just tells whether the program is running or not. – Kurt Bourbaki Feb 5 '13 at 11:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.