Author: Sahil Suri

AWK: Print header line and pattern match

AWK is a powerful regular expression filtering and pattern matching scripting language. Please consider heading to awk tutorials section to read through our other awesome AWK tutorials which deep dive into different aspects of the language. In this tutorial, we look at how we can use AWK to print the header lines from a file or a command output along with the pattern being searched. While filtering output from certain commands or lengthy reports, it may be important to display the first line of the file or the header line to make sense of the rest of the output which is being displayed. Consider the below output. [sahil@linuxnix ~]$ df -hTP Filesystem                   Type     Size  Used Avail Use% Mounted on /dev/mapper/vg_pbox6-lv_root ext4      18G  4.9G   12G  30% / tmpfs                        tmpfs    491M   80K  491M   1% /dev/shm /dev/sda1                    ext4     477M   35M  418M   8% /boot /dev/sr0                     iso9660  3.7G  3.7G     0 100% /media/CentOS_6.8_Final /dev/sdb                     ext4     488M  396K  462M   1% /u01 /dev/sdc                     ext4     488M  396K  462M   1% /u02   We would like to print only the ext4 type file systems but along with the header line as well to make sense of the values indicated by the respective fields. We could use grep to meet this requirement as done in the below command [sahil@linuxnix ~]$ df -hTP | grep -E "Filesystem|ext4" Filesystem                   Type     Size  Used Avail Use% Mounted on /dev/mapper/vg_pbox6-lv_root ext4      18G  4.9G   12G  30% / /dev/sda1                   ...

Read More

SAR command: ksar for GUI monitoring in Linux – Part 4

In the final article in this series, we’ll focus on generating a graphical view of sar data using ksar command because we’ve all heard the phrase a picture speaks a thousand words. Steps to install ksar in Linux Check and fix Java application Download ksar from SourceForge site Extract and install ksar application Working on prerequisites of KSAR application Ksar is a java based application which can be used to create a graphical representation of data collected by the sar command. ksar allows graphs to be collected in a variety of formats. It is easy to install and easy to use. The only major dependency is the presence of java on the system. Although JDK is usually installed on Linux systems by default but let’s verify just to be sure. Doing a quick search for jdk (java development kit) in the rpm -qa output gives a couple of results. [root@linuxnix ~]# rpm -qa | grep jdk java-1.6.0-openjdk- java-1.6.0-openjdk-javadoc- java-1.7.0-openjdk-devel- java-1.7.0-openjdk- java-1.6.0-openjdk-devel- We can verify that the java binary is available by using the which command to look for it. [root@linuxnix ~]# which java /usr/bin/java Now, let’s verify the rpm which actually provides this binary. [root@linuxnix ~]# ls -l /usr/bin/java lrwxrwxrwx. 1 root root 22 Sep 26 01:05 /usr/bin/java -> /etc/alternatives/java [root@linuxnix ~]# ls -l /etc/alternatives/java lrwxrwxrwx. 1 root root 46 Sep 26 01:05 /etc/alternatives/java -> /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java [root@linuxnix ~]# ls -l...

Read More

Linux SAR command: Report historical data – Part 3

SAR file collection and historical reporting data: In a previous article, we described how sar reports data on various system performance metrics in real time. In this article, we talk about sar data is collected, stored and retrieved. When we install sysstat, it adds the following additional utilities which are responsible for collecting and storing sar data: sadc: This tool collects sar data to make it available for retrieval at a later date. sa1: It saves system activities in a binary data file. sa1 depends on sadc to provide the data. sa2: It creates a daily summary of the collected statistics. sadf: Allows generation of sar report in CSV, XML, and other formats. Both sa1 and sa2 utilities run as cron jobs. The default sysstat cron file is /etc/cron.d/sysstat and is as follows: sudo cat /etc/cron.d/sysstat # Run system activity accounting tool every 10 minutes */10 * * * * root /usr/lib64/sa/sa1 1 1 # Generate a daily summary of process accounting at 23:53 53 23 * * * root /usr/lib64/sa/sa2 -A The file is root readable and thus requires superuser privileges to access. ls -l /etc/cron.d/sysstat -rw------- 1 root root 235 Mar  8  2016 /etc/cron.d/sysstat Let’s understand the two cron jobs mentioned above: The first sysstat cron job: /usr/local/lib/sa/sa1 It runs every 10 min and collects sar data for historical reference. This writes the data to /var/log/sa/saXX file....

Read More

Over 16,000 readers, Get fresh content from “The Linux juggernaut”

Email Subscribe


My photo
My name is Surendra Kumar Anne. I hail from Vijayawada which is cultural capital of south Indian state of Andhra Pradesh. I am a Linux evangelist who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. At present I work at Bank of America as Sr. Analyst Systems and Administration. You can contact me at surendra (@) linuxnix dot com.