Thursday, August 1, 2019

Combine two files in Linux and create one

To combine two or more files and create a single file with the content of all files clubbed:

Suppose we have 2 files namely file1 and file2.

File1 contains

this is file1 data

File2 contains

this is file2 data


Now, to combine Fiile1 and File2 

cat File1 File2 > File3

File3 will have the contents as

this is file1 data
this is file2 data

Thursday, July 25, 2019

Script for saving output of Linux commands to a text File

Purpose of the script:

Requirement: you want to monitor the utilization of a directory every hour. create the below script and schedule it to run for every hour.


First create a script file using Vi editor. and write the code like mentioned below
eg. vi test

#!/bin/bash
SID=$SAPSYSTEMNAME
echo "this will generate file for /usr/sap utilization for $SID" >> size.txt
df -h /usr/sap >> size.txt
date >> size.txt

This script will add the utilization of directory /usr/sap along with date in the txt file 'size.txt'

Output: 

This will generate file for /usr/sap utilization for PRD
Filesystem             Size   Used  Available Capacity  Mounted on
eu-prdci-test_bk/usr_sap   500M   306M       194M    62%    /usr/sap
Thu Jul 25 10:36:04 UTC 2019

this will generate file for /usr/sap utilization for PRD
Filesystem             Size   Used  Available Capacity  Mounted on
eu-prdci-test_bk/usr_sap   500M   306M       194M    62%    /usr/sap
Thu Jul 25 10:42:43 UTC 2019