Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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:

#!/bin/bash

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
add comment

2 Answers

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"
      ###COMMAND TO STOP XAMPP###
   else
      echo "Process is not running, starting"
      ###COMMAND TO START XAMPP###
 fi

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
add comment

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"
else
     echo "Process is not running"
fi

Hope this is waat you are looking for.

share|improve this answer
    
I don't know...it 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
add comment

Your Answer

 
discard

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.