Home > database >  How can we edit linux script?
How can we edit linux script?

Time:11-09

I want to monitor apaci service for ubuntu but below script is not working.


{

#! /bin/bash

if [ $(ps aux | grep apache2 | wc -l) -gt 1 ]; then

echo "Statistic:0"

else

echo "Statistic:1"

fi

exit 0;

}

I try this script dont work :(

{

#! /bin/bash

if [ $(ps aux | grep apache2 | wc -l) -gt 1 ]; then

echo "Statistic:0"

else

echo "Statistic:1"

fi

exit 0;

}

CodePudding user response:

I edited your question to make it readable - but I think it is working as expected once the format is cleaned up. It looks like you are trying to find out if apache2 is running.

#!/bin/bash

if [ $(ps aux | grep apache2 | wc -l) -gt 1 ]; then
  echo "Statistic:0"
else
  echo "Statistic:1"
fi

exit 0

Depending on what "flavor" of linux you are running, the following might be a better option for you. You can also use is-enabled, is-failed, to check other status.

if systemctl is-active -q apache2; then
  echo "Statistic:0"
else
  echo "Statistic:1"
fi

CodePudding user response:

Your script is working absolutely fine as per the code. Please define what kind of error you got.

Try running it on another machine like VMs or containers.

  • Related