Monitor server swap and restart PHP shell script _linux Shell

Source: Internet
Author: User
Tags fpm

Compromise, write a script to monitor swap bar, put in the crontab inside, 2 hours to execute once, the world is quiet, no annoying alarm text

Copy Code code as follows:

#!/bin/bash
function usage
{
echo "Usage: $ $"
echo "e.g $1500"
Exit
}
If [$#-lt 1];then
Usage
Fi
Typeset-i Nowswap Limitswap
Limitswap=$1
nowswap=$ (free-m|grep "Swap" |sed-e "s/\ (. *\) \:\ (. *\)/\2/g" |awk ' {print $} ')
If [$limitSwap-lt $nowSwap];then
While [1]
Todo
IF/ETC/INIT.D/PHP5-FPM Restart|grep-c fail
Then echo "[$ (date +%y/%m/%d0-%h:%m)]restart PHP failed"
Else
echo [$ (date +%y/%m/%d-%h:%m)]restart php successful! "
Break
Fi
Done
Fi

Note: if/etc/init.d/php5-fpm restart|grep-c fail This sentence in the middle of the command replaced by your own can

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.