Linux.com

Community Blogs



Linux Shell Script To Monitor Space Usage and Send Email

Linux shell script to check /var logs space and send email if used space reach 80%. Also print space usage of each directory inside /var. Useful to find out which folder use most of space under /var. This script really helps system administrator to monitor their servers space usage. Based on the requirement , administrators can change the directoires they want to monitor.

 

#!/bin/bash

LIMIT='80'

#Here we declare variable LIMIT with max of used spave

DIR='/var'

#Here we declare variable DIR with name of directory

MAILTO=' This e-mail address is being protected from spambots. You need JavaScript enabled to view it '

#Here we declare variable MAILTO with email address

SUBJECT="$DIR disk usage"

#Here we declare variable SUBJECT with subject of email

MAILX='mailx'

#Here we declare variable MAILX with mailx command that will send email

which $MAILX > /dev/null 2>&1

#Here we check if mailx command exist

if ! [ $? -eq 0 ]

#We check exit status of previous command if exit status not 0 this mean that mailx is not installed on system

then

          echo "Please install $MAILX"

#Here we warn user that mailx not installed

          exit 1

#Here we will exit from script

fi

cd $DIR

#To check real used size, we need to navigate to folder

USED=`df . | awk '{print $5}' | sed -ne 2p | cut -d"%" -f1`

#This line will get used space of partition where we currently, this will use df command, and get used space in %, and after cut % from value.

if [ $USED -gt $LIMIT ]

#If used space is bigger than LIMIT

then

      du -sh ${DIR}/* | $MAILX -s "$SUBJECT" "$MAILTO"

#This will print space usage by each directory inside directory $DIR, and after MAILX will send email with SUBJECT to MAILTO

fi

Sample Output

./check_var.sh

37M     /var/cache

32K     /var/db

8.0K    /var/empty

4.0K    /var/games

70M     /var/lib

4.0K    /var/local

8.0K    /var/lock

38M     /var/log

0       /var/mail

4.0K    /var/nis

4.0K    /var/opt

4.0K    /var/preserve

88K     /var/run

220K    /var/spool

37M     /var/tmp

24M     /var/www

4.0K    /var/yp

Read more linux shell scripts

 

 

Eztables: simple yet powerful firewall configuration for Linux

Anyone who ever has a need to setup a firewall on Linux may be interested in Eztables.

It doesn't matter if you need to protect a laptop, server or want to setup a network firewall. Eztables supports it all.

If you're not afraid to touch the command line and edit a text file, you may be quite pleased with Eztables. 

Some features:

  • Basic input / output filtering
  • Network address translation (NAT)
  • Port address translation (PAT)
  • Support for VLANs
  • Working with Groups / Objects to aggregate hosts and services
  • Logging to syslog
  • Support for plugins
  • Automatically detects all network interfaces

 

 

How to Install TeamViewer 9 on Linux

TeamViewer is very useful app for connecting remote systems with graphical environment in easy steps. Till now most of users used on it windows systems. But as the desktop users are switching to linux distribution's, So they will requires TeamViewer on linux desktop also.  

This article How to Install TeamViewer 9 on Linux Distributions will provide you easy steps to install it.

 

Transfer Linux data to ios

I have downloaded data files from Dish DVR to an external HDD.  Win7 can't see the HDD. I would like to transfer to DVD. Is there an easy way or am I barking up the wrong tree? I understand I can use the DVR to play through and record off the TV, but I was hoping to fnd an easier way. Does Nero have such ability? I have Nero and another conversion program, but I did't find how within those progrqms. Thanks

 

Install Nginx + Php FPM + APC on CentOS 6.4

LEMP server A lemp server runs Nginx web server along with Php and Mysql or MariaDB on a Linux system. Nginx is increasing becoming popular because of its lightweight structure and ability to handle large amounts of traffic in an optimum manner. Mariadb is the replacement for mysql because mysql is not very free anymore. In this tutorial we shall be setting up Nginx with Php FPM on CentOS. The instructions to instal MariaDB shall be covered in another post. CentOS is a very popular os for linux based web servers. CentOS (Community Enterprise Operating System) is based on RHEL (RedHat Enterprice Linux) and is 100% binary compatible with it. For us it simply means that its similar to rhel in its working and environment and that we have the handy yum command available to install software easily from the repositories. In this example we shall be working on CentOS 6.4 which, at the time of this post is a recent version. Install Nginx The first step is to install Nginx web server. Nginx is not available in the default CentOS repositories but nginx provides centos specific repositories for easy use. Add the nginx repository We create a repository file in /etc/yum.repos.d directory $ nano /etc/yum.repos.d/nginx.repo Now open the file and add the following lines. These instructions are provided by Nginx directly. [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1 Save and close. Now nginx can be installed. $ yum install nginx The above will download and install the nginx web server and make it ready to use. After the installation completes, its time to do some inspection. First use the service command to check the status of nginx. [root@dhcppc2 ~]# service nginx status nginx is stopped The above shows that nginx service is there but is stopped. Next check the configuration using the t option with nginx command. [root@dhcppc2 ~]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful The above command tells that the configuration is OK and all set to run. And most importantly, it also tells the location of the nginx configuration file. For creating virtual hosts/multiple domains, its important to create separate configuration files for each host. The virtual hosts configurations are located at /etc/nginx/conf.d/ OK, now lets start nginx server. [root@dhcppc2 conf.d]# service nginx start Starting nginx: [ OK ] Now nginx is up and running. Find the ip address of the nginx server using ifconfig and connect to that ip from a browser to test it out. http://192.168.1.4/ You might have to open port 80 on the centos server, if it is not already open. Check this tutorial on how to open http port on centos. Once its open the ip address of the nginx server should load the page with content like this Welcome to nginx! If you see this page, the nginx web...
Read more... Comment (0)
 

Install Apache web server on Ubuntu 13.10

Install Apache Web server A while back I updated my ubuntu to 13.10 and then the apache php installation got messed up. So I had to reinstall it quickly to continue working on my php projects. Apache is there in the ubuntu repositories so can be installed without much effort. Here is the quick command you need to fire at the terminal. $ sudo apt-get install apache2 Apache by default configures itself quickly so that you can open up it from the browser with the localhost url http://localhost/ The default web root directory is /var/www. So whatever files are put in this directory are accessible from the localhost url. Later we shall check how to change the default web root directory To check what version of apache is installed use the apache2 command with the v option/ $ apache2 -v Server version: Apache/2.4.6 (Ubuntu) Server built: Aug 9 2013 14:28:56 Locate configuration files To get more information about how exactly apache is configure on your system, use the apache2ctl command. $ apache2ctl -V AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message Server version: Apache/2.4.6 (Ubuntu) Server built: Aug 9 2013 14:28:56 Server's Module Magic Number: 20120211:23 Server loaded: APR 1.4.8, APR-UTIL 1.5.2 Compiled using: APR 1.4.8, APR-UTIL 1.5.2 Architecture: 64-bit Server MPM: prefork threaded: no forked: yes (variable process count) Server compiled with.... -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_SYSVSEM_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=256 -D HTTPD_ROOT="/etc/apache2" -D SUEXEC_BIN="/usr/lib/apache2/suexec" -D DEFAULT_PIDLOG="/var/run/apache2.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="mime.types" -D SERVER_CONFIG_FILE="apache2.conf" enlightened@enlightened:~$ It tells the name of the configuration file, the server mpm being used and lots of other details. These are useful when configuring apache further. The main configuration file is located at /etc/apache2/apache2.conf Just prepend the HTTPD_ROOT with SERVER_CONFIG_FILE to get the actual location of the configuration file. There are lots of configuration files involved with apache. The main configuration file is "apache2.conf" as mentioned above. This configuration file has instructions to load further configuration files along. Here is the line that does it. # Include generic snippets of statements IncludeOptional conf-enabled/*.conf # Include the virtual host configurations: IncludeOptional sites-enabled/*.conf Change web root directory To change the web root, we need to change the setting in the sites-enabled configuration files. As a standard practice a separate configuration file is created inside sites-enabled directory for each vhost or virtual host. A virtual host is a domain. So you can have multiple domains served by apache. In this example however we just use the default configuration file. There should be a file called 000-default.conf inside the /etc/apache2/sites-enabled directory. If its not there then copy it from /etc/apache2/sites-available. The file looks like this initially. <VirtualHost *:80> # The ServerName directive sets the...
Read more... Comment (0)
 

Xubuntu 13.10 review – good as always

Xubuntu 13.10 Its over a week since Xubuntu 13.10 was released which is based on Ubuntu 13.10 Saucy Salamander and I finally got time to take a look at it. If you are new to this, then know that Xubuntu is a Xfce desktop based spin/variant of Ubuntu. It is not a derivative, just the same ubuntu wrapped with the xfce desktop. So you got the same repositories of software to use and everything else that is there in the original Ubuntu. Xubuntu gives you all the power of ubuntu with a lightweight desktop that is not cumbersome to work with. Xfce offers a clean conventional style desktop ideal for those who want to focus more on getting things done. Xubuntu packs xfce with the greybird theme which makes the desktop look very pragmatic. Its my favorite theme on both Lubuntu and Xubuntu. Lightweight Ubuntu alternative The lightweight nature of xubuntu makes it a good choice for low-spec pcs and netbooks/notebooks where you don't want to waste resources un-necessarily. I use it on my Samsung n110 netbook without any issues. Xubuntu's simplicity also makes it ideal for work environments where functionality and productivity is most important. However, do not expect it to be super fast, because its only the desktop environment that is lightweight, the rest of ubuntu system (and linux beneath it) are in full size. Therefore its not a distro for slow/old machines. For slow and old machines you need an entirely lightweight linux distro like puppy linux. When using desktop like xfce or lxde with optimum configuration, you can definitely expect to free up some ram and cpu. Xubuntu being a close variant of Ubuntu sees most changes only in the desktop environment. Here is a list of updates that took place in 13.10 A new version of xfce4-settings has been uploaded,...
Read more... Comment (0)
 

5 commands to check memory usage on Linux

Memory Usage On linux, there are commands for almost everything, because the gui might not be always available. When working on servers only shell access is available and everything has to be done from these commands. So today we shall be checking the commands that can be used to check memory usage on a linux system. Memory include RAM and swap. It is often important to check memory usage and memory used per process on servers so that resources do not fall short and users are able to access the server. For example a website. If you are running a webserver, then the server must have enough memory to serve the visitors to the site. If not, the site would become very slow or even go down when there is a traffic spike, simply because memory would fall short. Its just like what happens on your desktop PC. free command The free command is the most simple and easy to use command to check memory usage on linux. Here is a quick example $ free -m total used free shared buffers cached Mem: 7976 6459 1517 0 865 2248 -/+ buffers/cache: 3344 4631 Swap: 1951 0 1951 The m option displays all data in MBs. The total os 7976 MB is the total amount of RAM installed on the system, that is 8GB. The used column shows the amount of RAM that has been used by linux, in this case around 6.4 GB. The output is pretty self explanatory. The catch over here is the cached and buffers column. The second line tells that 4.6 GB is free. This is the free memory in first line added with the buffers and cached amount of memory. Linux has the habit of caching lots of things for faster performance, so that memory can be freed and used if needed. The last line...

Read more... Comment (1)
 

Open http port ( 80 ) in iptables on CentOS

Iptables firewall I was recently setting up a web server on centos with nginx and php. The installation of nginx was fine, but the http port of the system was not accessible from outside. This is because centOS by default has some iptables firewall rules in effect. Only the ssh port (22) was accessible and remote shell worked. So its necessary to open up port 80 for webserver like nginx to work. Iptables is the firewall on linux that can be configured to accept or reject network traffic based on various kinds of packet level rulesets. So it is necessary to configure this firewall to enable connections on network ports. Iptables rules There are 2 ways to configure iptables to open up port 80. First is using the iptables command and second is by creating a configuration file. First check the existing iptables rules in effect. The command is quite simple. Here is a sample output. [root@dhcppc2 ~]# iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT icmp -- anywhere anywhere ACCEPT all -- anywhere anywhere ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) target prot opt source destination REJECT all -- anywhere anywhere reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) target prot opt source destination [root@dhcppc2 ~]# As can be seen in the output, there is...
Read more... Comment (0)
 

Monitor disk io on linux server with iotop and cron

Iotop - Disk Input Output usage Recently my server was giving notifications of disk io activity rising above a certain threshold at regular intervals. My first guess was that some cronjob task was causing that. So I tried to check various cron tasks to find out which task or process was causing the io burst. On servers specially its always a good practice to monitor resource usage to make sure that websites work fast and well. However searching manually is not quite easy and this is where utilities like iotop come in. iotop shows what or how much disk io are all current processes doing. Its quite easy to use. Just run it from a terminal and you should see some output like this Total DISK READ: 0.00 B/s | Total DISK WRITE: 106.14 K/s TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND 335 be/3 root 0.00 B/s 98.56 K/s 0.00 % 2.03 % [jbd2/sda6-8] 4096 be/4 www-data 0.00 B/s 0.00 B/s 0.00 % 0.00 % apache2 -k start 1 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % init 2 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kthreadd] 3 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [ksoftirqd/0] 4100 be/4 www-data 0.00 B/s 0.00 B/s 0.00 % 0.00 % apache2 -k start 5 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kworker/0:0H] 4102 be/4 www-data 0.00 B/s 0.00 B/s 0.00 % 0.00 % apache2 -k start 7 be/0 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [kworker/u:0H] 8 rt/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [migration/0] 9 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcu_bh] 10 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % [rcu_sched] As we can see, each row shows a certain process and the amount of data it is reading or writing to. This information is actually instantaneous, so iotop keeps updating the values at certain interval like 1 second. Running iotop like this just tells the current io usage. What if we want...
Read more... Comment (0)
 

Install the Pantheon desktop on Ubuntu

Pantheon desktop environment Pantheon is a new desktop environment that comes with elementary OS. It has a mac like look and feel and has been designed very well. It looks superb specially on laptops and can give you a cool looking desktop that you want to show off. It can be installed on Ubuntu if you want to get the elementary OS like look and feel without changing the OS. In this example we are installing it on Ubuntu 13.04 Add the elementary ppa to ubuntu The elementary ppa provides all the necessary packages to get...

Read more... Comment (0)
 
Page 8 of 126

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board