FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Found some scripts i wrote some time ago....





honken
.. that i dont use now days, but maybe someone else would like to have/use or something like that.

think they ware made to work on Debian, but with some modification can work on any linux system.
honken
Apache Check
Check to see apache is running, if not running, start it. If it dont start, send a email with a log.


Code:

#!/bin/bash




#
# Packages required to be able to run this script:
# apt-get install sendemail
# apt-get install libio-socket-ssl-perl
# apt-get install libnet-ssleay-perl
# services / depending on systems this application can have a different search path, do: whereis services
#

##
# Apache check
##

######
# Email settings
######
SUBJECT="APACHE ERROR: APACHE SERVER NOT STARTING"
EMAILTO="mail@to.com"
EMAILFROM="mail@from.com"
EMAILM="email.txt"
EMAILU="mail@to.send.from.com"
EMAILP="password"
EMAILS="-s smtp.gmail.com:587 -o tls=yes"


#####
# DO NOT EDIT BELOW THIS UNLESS YOU KNOW WHAT YOU ARE DOING
#####
UNAME="$(/bin/uname -n)"
APACHE="$(/usr/sbin/service apache2 status | awk '{ print $3}')"
APACHESTATUS=$APACHE
if [ $APACHESTATUS != running ] ; then
     APACHESTATUS=false
     echo "Apache is NOT running"
     if  [ $APACHESTATUS == false ] ; then
            echo "Starting Apache"
            /etc/init.d/apache2 start
            sleep 3
       else
            exit
fi
  else
     APACHESTATUS=true
     echo "Apache is running"
     exit
fi
sleep 10

APACHE="$(/usr/sbin/service apache2 status | awk '{ print $3}')"
APACHESTATUS=$APACHE

if [ $APACHESTATUS != running ] ; then
      APACHESTATUS=false
      if [ $APACHESTATUS != true ] ; then
            echo "Sending Email to System administrator informing about problem"
            echo "Server error detected on $UNAME at $(date +%Y:%m:%d-%H:%M)" > $EMAILM
            echo "" >> $EMAILM
            echo "Unable to start up apache webservice." >> $EMAILM
            echo "Please login and check log files." >> $EMAILM
            /usr/bin/sendemail -f $EMAILFROM -t $EMAILTO $EMAILS -xu $EMAILU -xp $EMAILP -m < $EMAILM -u $SUBJECT
  else
      exit
fi
  else
     APACHESTATUS=true
     echo "Apache is running"
     exit
fi


Note: You need to setup a cronjob to run this script.
honken
Apache Load
Created this when our webserver was having heavy load, and caused problems that we could not login to the server using SSH also

Not sure thou about the way it counts the memory usage, but it did the trick at that time.

Code:

#!/bin/bash


# Restart apache if load to high.


# Edit max value
MAX="80"


#####
# DO NOT EDIT
#####



CURRENT="$(ps aux |grep apache2 | awk '{ sum+=$4} END {print sum}')"
ROUND="$(echo "$CURRENT" | awk '{printf("%d\n",$0+=$0<0?-0.5:0.5)}')"


if [ "$ROUND" -gt "$MAX" ]; then
echo "$ROUND"
echo "Load grater than value $MAX"
echo "Restart Apache"
/etc/init.d/apache2 restart
else
echo "Load lower value $MAX"
echo "Continue as you where"
fi
honken
Apache Memory check
Think this is unfinished at some part, but it only displays % memory used blaha blaha.

Code:

#!/bin/bash

PROCESSNAME=apache2
MYPID="$(pidof $PROCESSNAME |awk '{ print $4}')"
RSS=`echo 0 $(cat /proc/$MYPID/smaps  | grep Rss | awk '{print $2}' | sed 's#^#+#') | bc;`
SHARED=`echo 0 $(cat /proc/$MYPID/smaps  | grep Shared | awk '{print $2}' | sed 's#^#+#') | bc;`
PRIVATE=`echo 0 $(cat /proc/$MYPID/smaps  | grep Private | awk '{print $2}' | sed 's#^#+#') | bc;`
SWAP=`echo 0 $(cat /proc/$MYPID/smaps  | grep Swap | awk '{print $2}' | sed 's#^#+#') | bc;`
PSS=`echo 0 $(cat /proc/$MYPID/smaps  | grep Pss | awk '{print $2}' | sed 's#^#+#') | bc;`
MEM=`echo "$RSS + $SHARED + $PRIVATE + $SWAP + $PSS"|bc -l`



TOTALMEM="$(free |grep Mem: | awk '{print $2}')"

PROCENT=`echo "scale=2; $MEM*100/$TOTALMEM" | bc`
P=`echo "scale=2; 0.8*$TOTALMEM" |bc`
#echo "Apache PID    "    ":"$MYPID
#echo "Apache uses   "    ":"$MEM
#echo "Total Mem     "    ":"$TOTALMEM
#echo "Procent used  "    ":"$PROCENT"%"
#echo "80 Procent is "    ":"$P


#echo "Indicator          ""Results"
#echo "============================";
#echo "PID                "$MYPID
#echo "USAGE (kb)         "$MEM
#echo "TOTAL MEM          "$TOTALMEM
#echo "PROCENT            "$PROCENT"%"
#echo "----------------------------";
#echo "MAX ALLOWED (kb)   "$P

echo ""
echo ""
echo ""
echo "Process            ""Pid               ""USAGE kb           ""USED %             "
echo "=================================================================================";
echo "$PROCESSNAME            $MYPID              $MEM               $PROCENT           "
echo "=================================================================================";
echo ""
echo ""
echo "Total Memory"
echo "============";
echo "$TOTALMEM""kb"
echo ""
echo ""
echo "Max allowed before service restart"
echo "==================================";
echo "$P""kb"
echo ""
echo ""
[/b]
spam
my, what incredibly useful scripts!
Related topics
PostgreSQL and Console Access
open DVD from CD-ROM - possible??
[php] travel agency script alike
I'm stumped - What kind of memory is this ?
Is Martial Arts Considered "Sports"?
Is this democracy?
Immunology
Monster of Loch Ness
:: whats your favorite lyrics ::
Collecting... bones?
Is Google is Still No.1 in Search Engine...
ejecting USB drive.
Is Really Indian did find water on Moon ?
My new lady... A cute Arabian filly (w/ pics, of course!)
Is El Qaeda still a force to be reckoned with?
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.