1

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

2 Answers 2

1

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 :)

1

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.

1
  • 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. Feb 5, 2013 at 11:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .