Script to send email alert when disk space usage is more than 70%

Hi,

This is a script for the linux administrators who wish to have the alerts of disk usage to be sent via email, then please run this script on your Linux box..


#!/bin/bash
usage=`df -h | awk '{print $5}' | sed -e N -e 's/\n/ /' | awk '{print $2}' | tr -d % -s "\n"`
devnm=`df -h | awk '{print $1}' | sed -e N -e 's/\n/ /' | awk '{print $2}' | tr -s "\n"`
str="============================="

if [ $usage -ge 70 ]; then
info="Disk usage for $devnm is more than 70% , Current Disk usage is $usage % "
echo -e "$str\n$info\n$str" |mail -s "Alert: Disk Usage for `hostname` on `date`" abc@yourdom.com

else
info="Disk Usage is $usage% for $devnm"
# echo -e "$str\n$info\n$str" | mail -s "Alert: Disk Usage for `hostname` on `date`" abc@yourdom.com
fi



How to check PHP version of your server ?


You can check Php Version using phpinfo file. You can create phpinfo.php from your Cpanel >> Filemanager Or You can crete it through shell also(if you have the access).
1) Create a phpinfo.php file under your public_html folder for respective host.
2) Edit phpinfo.php file using any editor like vi. add below code in the phpinfo.php file
Code:
< ?phpinfo();?>
Close and save the file
3) Permissions should be 644 for phpinfo.php. You could change the permission using the code given below.

Code:
chmod 644 phpinfo.php
4) Ownerships should be user:user. You could change the permission using the code given below.
Code:
chown username:username phpinfo.php
5) If you are using cPanel >> Go to Filemanager and create phpinfo.php file. Insert the phpinfo script as updated above, save the file then change the permission easily from the "permission" tab provided by cPanel.
6) Now check the php version of your host using link
http://domainname/phpinfo.php
Note : If server already has PHP5 installed.
5) If "http://domainname/phpinfo.php" which displays the version PHP 4 and you want to upgrade it php5
6) Then Create .htacess file under your public_html folder for respective domain.
7) Edit with your favorite editor and add following code in the .htaccess file.
Code:
AddHandler application/x-httpd-php5 .php
8) Permissions should be 644 for .htaccess. You could change the permission using the code given below.
Code:
chmod 644 .htaccess
9) Now visit "http://domainname/phpinfo.php" It should display the PHP 5 version.

linux VPS Commands

Utility vzctl runs on host server (HS) and performs direct manipulations with Container (CT).

Containers can be referred to by numeric ctid (or name which can be assigned with --name option).

Note
that CT ID <= 100 are reserved for Virtuozzo internal purposes.


Following commands turn the quota on or off for the particular Container; the vzctl quotainit command forces the quota to be initialized for the Container, i.e. its disk space and inodes recalculated. The Container ID must be specified after these commands with no additional options:

vzctl quotaon

vzctl quotaoff

vzctl quotainit

When the quota is turned on or initialized for the specified Container, the quota settings are taken from the Container configuration file. If you wish to change these settings, you should use the vzctl set command.


============================================

vzctl

vzctl is the primary tool for Container management. To use it, you have to log in to the Hardware Node as the root user. The syntax of vzctl is:
CT_ID>>>>is Container ID set

vzctl [--quiet | --verbose] command CT_ID

vzctl --version

vzctl --help

Where command can be one of the following:

convert : Used to convert legacy Containers to the new Virtuozzo Containers 4.0 directory layout.

create : Used to create Containers.

delete : Used to remove a Container.

Like vzctl delete, this command is also used to remove a Container from the Hardware Node.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mounting and Unmounting

vzctl mount CT_ID : Allows mounting the Container private area and executing the Container mount script.

vzctl umount CT_ID : Allows dismounting the Container private area and executing the unmount script.

start : Starts a Container.

stop : Stops a Container.

restart : Restarts a Container.

status : Displays the Container status.

vzctl set ctid :
This command sets various CT parameters. If flag --save is given, parameters are saved in CT configu
ration file ve.conf(5). If CT is currently running, vzctl applies these parameters to CT, in case
--setmode option specified apply logic for parameters that canĂ¢t be applied or tunning CT will be
changed, if restart -restart CT, if ignore - ignore error. Parameters that can not be applied run-
time are capability, quotaugidlimit, bindmount, and iptables.

The following options can be used with set command.

Miscellaneous parameters

--setmode restart|ignore
Change default mode for apply parameters that can not be applied on running CT. restart - restart CT,
ignore - ignore error.

--onboot yes|no
Sets whether this CT will be started during system boot up. CT will not be auto-started during system
boot up unless this parameter is set to yes.

--root path
Sets path to root directory for this CT. This is essentially a mount point for CT root. Value must
contain string $VEID, which will be substituted with numeric CT ID. Changing this parameter is not
recommended, better edit vz(5) global configuration file.

--userpasswd user:password
Sets password for given user in CT, creating the user if it does not exists. Note that this option is
not saved in configuration file at all (so --save flag is useless), it is applied to CT (by modifying
its /etc/passwd and /etc/shadow files).

In case CT root is not mounted, it is automatically mounted, then all appropriate file changes are
applied, then it is unmounted.

Note that CT area should be created before using this option.

--disabled yes|no :
Disable CT start. For force start disabled CT option --force can be used.

--name name :
Bind CT with name, it allows to use name unstead of CT ID. The valid symbols for name are [0-9][aA-
Zz][ -_.] and all international sybmols.

--description desc :
Assing description for CT. It can be viewed by vzlist utility.

--ipadd addr :
Network related parameters


vzctl start : Start the container

vzctl create {--pkgset [--pkgver ] | --ostemplate }
[--config ] [--private ] [--root ]
[--ipadd ] | [--hostname ] [--skip_app_templates] : Create Container with the package , configuration, allocating ipaddress, signing hostname , etc..

vzctl convert CT_ID :
In Virtuozzo 4.0 Container is created in new (4.0) layout. All private data (config,
scripts, quota) resides under CT private. Convert action convert Container from old to
4.0 layout.


vzctl set [--save] [--ipadd ] [--ipdel |all]
Used to set Container parameters, including resource control settings, the location of the Container private area, hostname, IP addresses, and Container root user password.

vzctl unset
: Used to remove Container parameters (resource control settings, IP addresses, etc.) from the configuration file.
vzctl enter
: Provides a way for the Hardware Node administrator to "enter" a Container without knowing the Container root password. Use this command with caution and never run it on un-trusted Containers.

exec, exec2 : These two commands allow running arbitrary commands inside a Container without logging in to the corresponding Container. The difference between two is the returned status.

vzctl recover : Recovers the original state of the Container system and application files in case something has been broken. The user files are left intact.

vzctl quotaon
: Turns the disk quota on for the given Container.

quotaoff
: Turns the disk quota off for the given Container.

quotainit
: Initializes the disk quota for the given Container with the parameters taken from the Container configuration file.


How to increase ip conntrack max value


First, find out the value of ip_conntrack_max using the command.

cat /proc/sys/net/ipv4/ip_conntrack_max

By default, the value is 34576.

Sometimes you can see the error "ip_conntrack Table full. Dropping packet" in the log file (/var/log/messages).

This error can be eliminated by increasing the value of this parameter.


Method # 1:

i) Execute the following line in the command prompt

echo 65536 > /proc/sys/net/ipv4/ip_conntrack_max

ii) Execute the command sysctl -p to flush the values

Note: This value will be restored once the server rebooted.


Method # 2:

i) Add the following line in '/etc/sysctl.conf' file

net.ipv4.netfilter.ip_conntrack_max = "65536"

ii) Execute the command sysctl -p to flush the values

Note: When we modify the value using this method, the value won't be restored even though we reboot the server.


Issue:

Sometimes we reset the value of ip_conntrack_max to 65536. But, it will restore to 34576 once we restart APF in the server.

Steps to fix this issue:

1. Open APF configuration file - /etc/apf/conf.apf
2. Find the line "SYSCTL_CONNTRACK"
3. The value sholuld be "34576". Change it to "65536".
4. Now refresh the firewall using the command "apf -r"
5. Check the value "cat /proc/sys/net/ipv4/ip_conntrack_max"



Error Cause:
Iptables under Linux maintains a list of connections passing through the router. Each connection tracking entry contains defined characteristics of the packet, including the source and destination IP address and port number. The connection tracking entries are ultimately stored in a hash table with a fixed size. If the router reaches the maximum number of connection tracking entries, it will log an error:

"ip_conntrack: table full, dropping packet"

The maximum size of the connection tracking table can be increased. The maximum size value is stored in the router's proc filesystem in the file /proc/sys/net/ipv4/ip_conntrack_max. Increasing the maximum size of the connection tracking table to a value larger than the total number of connections will eliminate the error message and prevent the router from dropping connections due to a lack of space in the connection tracking table.


Pages