Difference between revisions of "Scripts"

From Server Knowledge Base
Jump to navigationJump to search
m
 
(18 intermediate revisions by the same user not shown)
Line 3: Line 3:
Read the README.txt for further information on these tools. The number count below is only counting .sh and .pl files.
Read the README.txt for further information on these tools. The number count below is only counting .sh and .pl files.


All of these can be retrieved by clicking the Topic Header on this page, right clicking the link - Copy Link Address, then do:
All of these can be retrieved by clicking the Topic Header on this page, right clicking the link - Copy Link Address, then do either:


wget domain.co.uk/linktofile.sh
<pre>wget serverkb.co.uk/tools/linktofile.sh
wget -O - serverkb.co.uk/tools/linktofile.sh | bash</pre>


== [http://serverkb.co.uk/tools/accounts.sh Plesk Accounts] (1) -accounts.sh ==
== accounts.sh - [http://serverkb.co.uk/tools/accounts.sh Plesk Accounts] ==


The accounts script is only used on Linux servers with Plesk below version 11 (11+ encrypts passwords) and can retrieve Plesk, FTP and email passwords. To use it you need to do the following within [[SSH]]:
The accounts script is only used on Linux servers with Plesk below version 11 (11+ encrypts passwords) and can retrieve Plesk, FTP and email passwords. To use it you need to do the following within [[SSH]]:
Line 14: Line 15:
./accounts.sh</pre>
./accounts.sh</pre>


Written by Leon_Teale, modified by Byron Galietta and Sam Teale.
<!-- Written by Leon_Teale, modified by Byron Galietta and Sam Teale. -->


== [http://serverkb.co.uk/tools/advancedmonitor.sh Advanced Service Monitor] (2) - advancedmonitor.sh ==
== advancedmonitor.sh - [http://serverkb.co.uk/tools/advancedmonitor.sh Advanced Service Monitor] ==


This is a more advanced version a previous service monitor script , giving more output and debug possibilities.
This is a more advanced version a previous service monitor script , giving more output and debug possibilities.
Line 41: Line 42:
For example for MySQL have service="mysql" instead (or mysqld)
For example for MySQL have service="mysql" instead (or mysqld)


== [http://serverkb.co.uk/tools/backupdb.sh Backup databases on Plesk server] (3) - backupdb.sh ==
== betterqmqmtool.sh - http://serverkb.co.uk/tools/betterqmqtool.sh ==


This backs up all databases as .sql files and a .tar.gz containing all excluding information_schema, atmail and horde on a '''Plesk''' Linux server but does not email you them.
This is just a better version of the well known qmqtool from here: http://jeremy.kister.net/code/qmqtool/files/


=== [http://serverkb.co.uk/tools/databasedump.sh Email version] (4) - databasedump.sh ===
qmqtool manages qmail queue


This backs up all databases as .sql files and a .tar.gz containing all .sql excluding information_schema, atmail and horde on a '''Plesk''' Linux server '''and emails you them.'''
== chrootdbdump.sh - [http://serverkb.co.uk/tools/sqldump.sh SQL Backup for chroot] ==


=== [http://serverkb.co.uk/tools/dbsqlonlyEmailDump.sh Only .sql files] (5) - dbSQLonly.sh ===
This backs up databases from a chrooted Linux environment and places them in a folder called /sqlbak
 
Before using it please do:
 
chroot /usr/fs
 
=== chrootdbdumptoemail.sh - [http://serverkb.co.uk/tools/sqldumpmail.sh Email version] ===
 
== dbdump.sh - [http://serverkb.co.uk/tools/databasedump.sh Backup/dump databases on a Plesk server] ==
 
This backs up all databases as '''.sql files and a .tar.gz''' containing all excluding information_schema, atmail and horde on a '''Plesk''' Linux server but does not email you them.
 
=== dbdumponeemail.sh - [http://serverkb.co.uk/tools/dbdumponeemail.sh Email version] ===
 
This backs up all databases as '''.sql files and a .tar.gz''' containing all .sql excluding information_schema, atmail and horde on a Linux server with the '''Plesk control but '''does email you them.'''
 
=== dbdumpsepemails.sh - [http://serverkb.co.uk/tools/dbdumpsepemails.sh Only .sql files]===


Use this script if you only want .sql files in separate emails and not the extra one with all MySQL databases compressed into a .tar.gz.
Use this script if you only want .sql files in separate emails and not the extra one with all MySQL databases compressed into a .tar.gz.
Line 74: Line 91:
Could not send the message.</pre>
Could not send the message.</pre>


== [http://serverkb.co.uk/tools/disklimit.sh Disk Limit Monitor] (6) - disklimit.sh ==
== disablemail.sh - [http://serverkb.co.uk/tools/disablemail.sh Disable mail for multiple domains in Plesk] ==
 
== disklimit.sh - [http://serverkb.co.uk/tools/disklimit.sh Disk Limit Monitor] ==


This simply notifies you via email when your disk space reaches 90%. To run and install it do the following:
This simply notifies you via email when your disk space reaches 90%. To run and install it do the following:
Line 89: Line 108:
<pre>45 * * * * /root/disklimit.sh</pre>
<pre>45 * * * * /root/disklimit.sh</pre>


== [http://serverkb.co.uk/tools/domaintoip.sh Domain to IP conversion] (7) - domaintoip.sh ==
== domaintoip.sh - [http://serverkb.co.uk/tools/domaintoip.sh Domain to IP conversion] ==


This finds the IP addresses for all domains in /var/www/vhosts (this path can be edited) and outputs the results to screen and a file.
This finds the IP addresses for all domains in /var/www/vhosts (this path can be edited) and outputs the results to screen and a file.


== [http://serverkb.co.uk/tools/epel.sh Enable the EPEL repository] (8) - epel.sh ==
== doswatchauto.sh - http://serverkb.co.uk/tools/doswatchauto.sh ==
 
This tool is used to monitor an IP address on your server for traffic directed towards a specific service.
 
== doswatchmanual.sh - http://serverkb.co.uk/tools/doswatchmanual.sh ==
 
This tool is used to monitor an IP address on your server for traffic directed towards Apache.
 
== epel.sh - [http://serverkb.co.uk/tools/epel.sh Enable the EPEL repository] ==


This will take into account if the Operating System is CentOS or Ubuntu.
This will take into account if the Operating System is CentOS or Ubuntu.


== [http://serverkb.co.uk/tools/extralogging.sh Extra Logging] (9) - extralogging.sh ==
== extralogging.sh - [http://serverkb.co.uk/tools/extralogging.sh Extra Logging V.1] ==


[http://serverkb.co.uk/tools/extralogging2.sh Extra Logging 2] (for Plesk servers)
=== extralogging2.sh - [http://serverkb.co.uk/tools/extralogging2.sh Extra Logging V.1] ===


== [http://serverkb.co.uk/tools/findnameserver.sh Nameserver checker for a list of domains] (11) ==
For Plesk servers.


== [http://serverkb.co.uk/tools/findregistrar.sh Registrar finder for Plesk servers] (12) ==
== findnameserver.sh - [http://serverkb.co.uk/tools/findnameserver.sh Nameserver checker for a list of domains] ==
 
== findregistrar.sh - [http://serverkb.co.uk/tools/findregistrar.sh Registrar finder on Plesk servers] ==


Once edited with the registrar of your choice this will get the list of your domains and look up the domain registar. If it matches then it will place these in a file in the same directory you are in called our_registrar. Some server configuration has to be done first which can be found here: http://serverkb.co.uk/wiki/Linux#WHOIS_script
Once edited with the registrar of your choice this will get the list of your domains and look up the domain registar. If it matches then it will place these in a file in the same directory you are in called our_registrar. Some server configuration has to be done first which can be found here: http://serverkb.co.uk/wiki/Linux#WHOIS_script


== [http://serverkb.co.uk/tools/getdns.sh Retrieve all DNS from nameservers] (13) ==
== getdnsrec.sh - [http://serverkb.co.uk/tools/getdns.sh Retrieve all DNS from nameservers] ==


== [http://serverkb.co.uk/tools/maildisable.sh Disable mail for multiple domains in Plesk] (14) ==
== load.sh - [http://serverkb.co.uk/tools/load.sh Load and Domain access checker] ==
 
Shows the load and any domains that are currently being accessed (live) on a Plesk server.


== Mail Queue Count and Mail Warning (15 + 16) ==
== Mail Queue Count and Mail Warning (15 + 16) ==
Line 118: Line 149:
[http://serverkb.co.uk/tools/mailwarning.sh mailwarning.sh] runs every five minutes and will email you if your qmail mail queue is over the limit you set within it.
[http://serverkb.co.uk/tools/mailwarning.sh mailwarning.sh] runs every five minutes and will email you if your qmail mail queue is over the limit you set within it.


== [http://serverkb.co.uk/tools/mcrypt.sh Install mcrypt] (17) - mcrypt.sh ==
== mcrypt.sh - [http://serverkb.co.uk/tools/mcrypt.sh Install mcrypt] ==


This will install mcrypt on Ubuntu, CentOS 5 or CentOS 6. It will also automatically enable the EPEL repository if needed.
This will install mcrypt on Ubuntu, CentOS 5 or CentOS 6. It will also automatically enable the EPEL repository if needed.


== [http://serverkb.co.uk/tools/mysqltuner.pl MySQL Tuner] (18) - mysqltuner.pl ==
== memcpu.sh - [http://serverkb.co.uk/tools/memcpu.sh Memory + CPU checker] ==
 
Shows the RAM and CPU usage in the following format:
 
<pre>-------Mon Jun 24 19:48:01 BST 2013--------
PROCESS          %MEM %CPU
apache      0.0  0.6
mysql  0.4  2.0
java            14.1  6.3</pre>
 
== mysqltuner.pl - [http://serverkb.co.uk/tools/mysqltuner.pl MySQL Tuner] ==


This will only review your MySQL setup/performance, it will not make any changes.
This will only review your MySQL setup/performance, it will not make any changes.
Line 128: Line 169:
wget http://serverkb.co.uk/tools/mysqltuner.pl ; chmod +x ; perl mysqltuner.pl
wget http://serverkb.co.uk/tools/mysqltuner.pl ; chmod +x ; perl mysqltuner.pl


== [http://serverkb.co.uk/tools/nginxmon.sh Engine X Monitor] (20) - nginxmon.sh ==
== nginxmon.sh - [http://serverkb.co.uk/tools/nginxmon.sh Engine X Monitor]==


This is a script to automatically monitor and check the new web server used by Plesk 11+ on Linux servers. To use it, do the following:
This is a script to automatically monitor and check the new web server used by Plesk 11+ on Linux servers. To use it, do the following:
Line 143: Line 184:
vim nginxmon.sh</pre>
vim nginxmon.sh</pre>


== [http://serverkb.co.uk/tools/oldextralog.sh Old Extra Logging] (21) - oldextralog.sh ==
== oldextralogging.sh - [http://serverkb.co.uk/tools/oldextralog.sh Old Extra Logging] ==


== [http://serverkb.co.uk/tools/red5-1.0.0-RC1.tar.gz Red5 Media Server tar.gz] (25) ==
== phptimezone.sh - [http://serverkb.co.uk/tools/phptimezone.sh PHP Timezone correction] ==


See the following link for what Red5 is/does: http://www.red5.org/
This script corrects the PHP5 timezone setting on Debian/Ubuntu and CentOS servers.
<!-- == [http://serverkb.co.uk/tools/servicestarter.sh Plesk Monitor/Starter] ==
 
== pleskSSLchecker.sh - [http://serverkb.co.uk/tools/pleskSSLchecker.sh Plesk SSL checker] ==
 
On a Plesk server this will check all SSLs that are in either of the Plesk Domain or Server repositories.


This is a work in progress and is meant to start a specific service, in this case, Plesk. -->
== slow.sh - [http://serverkb.co.uk/tools/slow.sh Slow Query Log for MySQL] ==
== [http://serverkb.co.uk/tools/slow.sh Slow Query Log for MySQL] (22) - slow.sh ==


HN
HN
Line 167: Line 210:
} -->
} -->


== [http://serverkb.co.uk/tools/snow.sh Snow Script] (23) - snow.sh ==
== Software ==
 
=== [http://serverkb.co.uk/tools/software/red5-1.0.0-RC1.tar.gz Red5 Media Server tar.gz] ===
 
See the following link for what Red5 is/does: http://www.red5.org/
<!-- == [http://serverkb.co.uk/tools/servicestarter.sh Plesk Monitor/Starter] ==
 
This is a work in progress and is meant to start a specific service, in this case, Plesk. -->
 
== snow.sh - [http://serverkb.co.uk/tools/snow.sh Snowfall Script] ==


<pre>wget http://serverkb.co.uk/tools/snow.sh
<pre>wget http://serverkb.co.uk/tools/snow.sh
Line 178: Line 230:
CTRL + L
CTRL + L


== [http://serverkb.co.uk/tools/sqldump.sh SQL Backup for chroot] (24) - sqldump.sh ==
== updatedb.sh - [http://serverkb.co.uk/tools/updatedb.sh UpdateDB] ==
 
This backs up databases from a chrooted Linux environment and places them in a folder called /sqlbak
 
Before using it please do:
 
chroot /usr/fs
 
=== [http://serverkb.co.uk/tools/sqldumpmail.sh Email version] (25) - sqldumpmail.sh ===


== [http://serverkb.co.uk/tools/updatedbscript.sh UpdateDB] (26) - updatedbscript.sh ==
This was just a test. You can just add `updatedb`


This updates the linux index of a server if it does not already so any knew files can be found using the linux comand locate <filename>. To use it you need to do the following:
This updates the linux index of a server if it does not already so any knew files can be found using the command locate <filename>. To use it you need to do the following:


<pre>cd /root ; wget http://serverkb.co.uk/tools/updatedbscript.sh ; chmod +x updatedbscript.sh
<pre>cd /root ; wget http://serverkb.co.uk/tools/updatedbscript.sh ; chmod +x updatedbscript.sh

Latest revision as of 08:00, 12 June 2019

These are located at http://serverkb.co.uk/tools/

Read the README.txt for further information on these tools. The number count below is only counting .sh and .pl files.

All of these can be retrieved by clicking the Topic Header on this page, right clicking the link - Copy Link Address, then do either:

wget serverkb.co.uk/tools/linktofile.sh
wget -O - serverkb.co.uk/tools/linktofile.sh | bash

accounts.sh - Plesk Accounts

The accounts script is only used on Linux servers with Plesk below version 11 (11+ encrypts passwords) and can retrieve Plesk, FTP and email passwords. To use it you need to do the following within SSH:

wget http://serverkb.co.uk/tools/accounts.sh ; chmod +x accounts.sh
./accounts.sh


advancedmonitor.sh - Advanced Service Monitor

This is a more advanced version a previous service monitor script , giving more output and debug possibilities.

This script will monitor and start/restart a specific service that you specify. By default it will do Apache, the Linux web server. To use it, do the following:

cd / root ; wget http://serverkb.co.uk/tools/advancedmonitor.sh ; chmod +x advancedmonitor.sh
crontab -e

In here add:

10 * * * * /root/advancedmonitor.sh

Edit the file and replace the admin email address with yours by doing:

vim advancedmonitor.sh

Replace apache2 with httpd within it if your server calls Apache httpd instead.

To start another service edit the following field:

service="apache2"

For example for MySQL have service="mysql" instead (or mysqld)

betterqmqmtool.sh - http://serverkb.co.uk/tools/betterqmqtool.sh

This is just a better version of the well known qmqtool from here: http://jeremy.kister.net/code/qmqtool/files/

qmqtool manages qmail queue

chrootdbdump.sh - SQL Backup for chroot

This backs up databases from a chrooted Linux environment and places them in a folder called /sqlbak

Before using it please do:

chroot /usr/fs

chrootdbdumptoemail.sh - Email version

dbdump.sh - Backup/dump databases on a Plesk server

This backs up all databases as .sql files and a .tar.gz containing all excluding information_schema, atmail and horde on a Plesk Linux server but does not email you them.

dbdumponeemail.sh - Email version

This backs up all databases as .sql files and a .tar.gz containing all .sql excluding information_schema, atmail and horde on a Linux server with the Plesk control but does email you them.

dbdumpsepemails.sh - Only .sql files

Use this script if you only want .sql files in separate emails and not the extra one with all MySQL databases compressed into a .tar.gz.

For both of the above:

apt-get install mutt

or

yum install mutt
chmod 755 /sent ; chmod 755 /root/sent
vim /etc/passwd

Change the root user's home directory to / instead of /root

crontab -e

*  * * * 0 :> /root/sent

A solution may be needed for:

postdrop: warning: uid=0: File too large
sendmail: fatal: root(0): message file too big
Error sending message, child exited 75 (Deferred.).
Could not send the message.

disablemail.sh - Disable mail for multiple domains in Plesk

disklimit.sh - Disk Limit Monitor

This simply notifies you via email when your disk space reaches 90%. To run and install it do the following:

cd /root ; wget http://serverkb.co.uk/tools/disklimit.sh ; chmod +x disklimit.sh

Edit the file and replace the ADMIN email address with yours by doing:

vim disklimit.sh
crontab -e

In here add:

45 * * * * /root/disklimit.sh

domaintoip.sh - Domain to IP conversion

This finds the IP addresses for all domains in /var/www/vhosts (this path can be edited) and outputs the results to screen and a file.

doswatchauto.sh - http://serverkb.co.uk/tools/doswatchauto.sh

This tool is used to monitor an IP address on your server for traffic directed towards a specific service.

doswatchmanual.sh - http://serverkb.co.uk/tools/doswatchmanual.sh

This tool is used to monitor an IP address on your server for traffic directed towards Apache.

epel.sh - Enable the EPEL repository

This will take into account if the Operating System is CentOS or Ubuntu.

extralogging.sh - Extra Logging V.1

extralogging2.sh - Extra Logging V.1

For Plesk servers.

findnameserver.sh - Nameserver checker for a list of domains

findregistrar.sh - Registrar finder on Plesk servers

Once edited with the registrar of your choice this will get the list of your domains and look up the domain registar. If it matches then it will place these in a file in the same directory you are in called our_registrar. Some server configuration has to be done first which can be found here: http://serverkb.co.uk/wiki/Linux#WHOIS_script

getdnsrec.sh - Retrieve all DNS from nameservers

load.sh - Load and Domain access checker

Shows the load and any domains that are currently being accessed (live) on a Plesk server.

Mail Queue Count and Mail Warning (15 + 16)

These go together.

mailqueuecount.sh gets a queue status once a day.
mailwarning.sh runs every five minutes and will email you if your qmail mail queue is over the limit you set within it.

mcrypt.sh - Install mcrypt

This will install mcrypt on Ubuntu, CentOS 5 or CentOS 6. It will also automatically enable the EPEL repository if needed.

memcpu.sh - Memory + CPU checker

Shows the RAM and CPU usage in the following format:

-------Mon Jun 24 19:48:01 BST 2013--------
PROCESS          %MEM %CPU
apache      0.0  0.6
mysql  0.4  2.0
java            14.1  6.3

mysqltuner.pl - MySQL Tuner

This will only review your MySQL setup/performance, it will not make any changes.

wget http://serverkb.co.uk/tools/mysqltuner.pl ; chmod +x ; perl mysqltuner.pl

nginxmon.sh - Engine X Monitor

This is a script to automatically monitor and check the new web server used by Plesk 11+ on Linux servers. To use it, do the following:

cd /root ; wget http://serverkb.co.uk/tools/nginxmon.sh ; chmod +x nginxmon.sh
crontab -e

#In here add:

10 * * * * /root/nginxmon.sh

#Edit the file and replace the admin email address with yours by doing:

vim nginxmon.sh

oldextralogging.sh - Old Extra Logging

phptimezone.sh - PHP Timezone correction

This script corrects the PHP5 timezone setting on Debian/Ubuntu and CentOS servers.

pleskSSLchecker.sh - Plesk SSL checker

On a Plesk server this will check all SSLs that are in either of the Plesk Domain or Server repositories.

slow.sh - Slow Query Log for MySQL

HN

Software

Red5 Media Server tar.gz

See the following link for what Red5 is/does: http://www.red5.org/

snow.sh - Snowfall Script

wget http://serverkb.co.uk/tools/snow.sh
chmod +x snow.sh
./snow.sh

This puts snowfall on your screen! :) To quit, do:

CTRL + C
CTRL + L

updatedb.sh - UpdateDB

This was just a test. You can just add `updatedb`

This updates the linux index of a server if it does not already so any knew files can be found using the command locate <filename>. To use it you need to do the following:

cd /root ; wget http://serverkb.co.uk/tools/updatedbscript.sh ; chmod +x updatedbscript.sh
crontab -e

#In here add:

5 * * * * /path/to/updatedbscript.sh

eXample .htaccess and .htpasswd file

Place the below .htaccess file in your document root with 644 permissions.

Options +Indexes
AuthName "Private zone"
AuthType Basic
AuthUserFile /change/this/to/full/file/path/to/.htpasswd
require valid-user

Encrypt your password by doing:

openssl passwd -1
Password: *enter your password*
Verifying - Password: *enter your password again*
<Password will appear here>

Copy the encrypted password above.

Place the below .htpasswd file anywhere in the file system:

user:EncryptedPassword

Test by going to domain.co.uk/folder

Notes

Remove spaces between file names

Guide 1

Do not use for-loops to process lists of unknown length, like a directory listing. If the list grows too long it will exceed your maximum line length (see syslimits.h) and your code will break. Using a while-loop removes this risk.

Guide 2

Realtime monitor of Apache accesslog

vim realtime.sh
#!/bin/bash
ACCESSLOG="/var/log/apache2/access_log"
DATE=`date +%d\/%b\/%Y`
TOTAL=`netstat -pant | grep :80 | wc -l`

echo "There are a total of $TOTAL port 80 connections."
echo -ne "The " ; uptime | awk '{print $8,$9,$10,$11,$12}' ; echo ""

tail -10 $ACCESSLOG | grep $DATE" | awk '{ x = $2 " " $4 " " $7 ; printf "%-15s %-20s \n", $1, x, $7}'

Run this with:

watch -n 2 ./realtime.sh

Alternatively you can use httpry. This may be best run in a screen session so you can enter in and out of it. To use it do:

wget dldmz.eu/s/httpry
chmod +x httpry
./httpry

Then go to your websites. You can output the contents to a file by using:

./httpry -o filename