Friday, June 29, 2018

Command to check partition in Linux

In Fedora Linux below command can be used to check storage partition.

cat proc partitions

Sample output:

Major is the driver version. Minor tells us which disk or which controller it is using. Blocks is the size of disk in blocks. We can see the storage sda has seven partition sda, sda1, sda2 to sda6.

Alternative command:

You can use fdisk and then p command to print info about the partition.


Thursday, June 28, 2018

Get SAR report in CSV

To get SAR report in CSV use sadf command.

To get memory report


sadf -d /var/log/sa/sa20 -- -r

In the above command sa20 is sar file of day 20. You can give any value between 1 to 31. 
-r gets you memory report.

Instead -r you can use following options:

To get report for CPU, Disk etc

# -d activity per block device
# -b IO and transfer rates
# -q load
# -u cpu
# -r memory utilization
# -R memory
# -B paging
# -S swap space utilization
# -W swap stats
# -n network
# -v kernel filesystem stats

# -w  context switches and task creation

CSV report will be needed if you wanted to visualize it in Excel or plotting in software such as Tableau, SAS, Python, PHP, JavaScript etc

Wednesday, June 27, 2018

Script to get name of the program running

Use the below line to get name of the program that you are currently running inside the script. This will be mostly used if you want to display how to run the script you have created.

To get current program name inside the script:

script_name=$(basename $0)

You can use it like below:

if [[ $# -eq 0 ]]; then
echo "$script_name -h for more information" 1>&2
exit 254
fi