Server Monitoring Scripts and commands

Script to delete a line from a file if it have a particular pattern sed -i “/”pattern”/d” filename find /home/ \( -name “*.php” -o -name “*.html” -o -iname “*.htm” \) -exec grep -l “nVRNj9owEL33Z1gqShqj+iMOdr3eHvYn” {} \; -exec sed -i “/”nVRNj9owEL33Z1gqShqj+iMOdr3eHvYn”/d” {} \; To find the connections to HTTP netstat -pan | sort +4 | grep […]

Script to automatically start Nginx

You can use the following script to auto restart the nginx on the server. The following script check the status and if it is down then it restart. You can set cron  “* * * * * /bin/sh /root/autongnixrestart.sh”   #! /bin/sh set -e PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC=”nginx daemon” NAME=nginx DAEMON= /usr/sbin/$NAME SCRIPTNAME=/etc/init.d/$NAME test -x $DAEMON || exit […]

Script to automatically start mysql

The following script is used to  start mysql automatically when it is failed or stopped on the server. You can set 2 min cron “*/2 * * * * /bin/sh /root/automysqlstart.sh” and it restart the mysql automatically. #!/bin/bash #Checking whether MySQL is alive or not if mysqladmin ping | grep -q “alive”; then echo “MySQL is up” […]