Sponsored Content
Top Forums Shell Programming and Scripting Required formatted output on mail for disk utilization Post 303010678 by rbatte1 on Friday 5th of January 2018 07:22:00 AM
Old 01-05-2018
I think it is because your df output that you are reading into awk may be split over multiple lines if the logical volume name or mount-mount are too long.


Before I worry about that, there are a lot of file IO redirections here and a big long linst making it rather messy. Would something like this this be neater?
Code:
#!/bin/bash

Target_dirs="\
/Baysquar2/undo   \
/Baysquar2/redo1  \
/Baysquar2/redo2  \
/Baysquar2/temp   \
/Baysquar2/arch01 \
..... etc.
/Baysquar2/disk13 \
"                                                        # Clear list of directories defined, and easy to adjust

{
echo "Hello"
echo
echo "Size |Used |Avail|Use% |Mounted"                   # Manually set the headings
for dir in "$Target_dirs"
do
   df -h $dir
done | grep -v "Filesystem"                              # .... plus whatever formatting needed here
echo
echo "Bye"
} > output_file                                          #  All output within the braces written as a single IO, reducing clutter too


This looks much cleaner to me so you can concentrate on your formatting.

For the formatting loop, perhaps this might work:-
Code:
while read lv size used avail usep mounted
do
   if [ -z "$mounted" ]
   then                                                   # Line is split, so shuffle everything over
      mounted="$usep"                                     # Maybe an array could be used to smarten this
      usep="$avail"                                       # to a single step
      avail="$used"
      used="$size"
      size="$lv"
   fi
   printf "%-5s|%-5s|%-5s|%-5s|%-s" "$size" "$used" "$avail" "$usep" "$mounted"
done < <(for dir in "$Target_dirs"                        # .... whatever
do
   df -h "$dir"
done | grep -v "Filesystem")

Of course, you could use awk for this, but you need to know what input you are really getting for each 'line' that whatever tool will use.

Is the output you have shared scraped from the email or is that what ends up in the file?

Can you share the output for a simple df -h /Baysquar2/* /Taticr/* or the more explicit:
Code:
df -hP /Baysquar2/undo /Baysquar2/redo1 /Baysquar2/redo2 /Baysquar2/temp /Baysquar2/arch01 /Baysquar2/disk04 /Baysquar2/disk03 /Baysquar2/disk02 /Baysquar2/disk01 /Tat
icr/data04 /Taticr/data05 /Baysquar2/disk08 /Baysquar2/disk07 /Baysquar2/disk06 /Baysquar2/disk05 /Baysquar2/arch02_new /Baysquar2/disk09 /Baysquar2/disk10 /Baysquar2/
disk11 /Baysquar2/disk12 /Baysquar2/disk13


Can you tell me if my suggestions help/hinder/confuse?




Thanks, in advance,
Robin
 

7 More Discussions You Might Find Interesting

1. Red Hat

Disk Utilization is very high

Hi, I have monitored that disk utilization is very high on one of red hat linux VM. Would like to know how to find out that issue of high disk utilization is because of disk or Installed Application on that server is causing the problem. Regards, Manoj (1 Reply)
Discussion started by: manoj.solaris
1 Replies

2. Infrastructure Monitoring

Disk Utilization between Global + Zone

Dear Gentleman in my environment I have Solaris10 OS Box in Global Zone with 136 GB and mount point from SAN Storage 500 GB (Orastorage) Zone1 mounted on /Zones folder with 66 GB when I run zpool list output -bash-3.00$ zpool list NAME SIZE ALLOC FREE CAP HEALTH... (0 Replies)
Discussion started by: Hosam
0 Replies

3. Red Hat

Disk Utilization

Hi, Can anybody explain why my newly created 120G FS shows 100% utilization when only 113G of disk space has been used? ...... # df -h . Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg01-lvol0 119G 113G 0 100% /u02 #du -h /u02 16K ... (3 Replies)
Discussion started by: Duffs22
3 Replies

4. UNIX for Dummies Questions & Answers

Disk utilization

Hi, I have hundred folders under a fs /apps which is used by different users and they upload their data to these folders on a daily basis. Using du -sk gives me complete structure of the filesystem but i want to find out day to day utlization of the top ten highest accoriding to size wise ... (4 Replies)
Discussion started by: chetansingh23
4 Replies

5. Shell Programming and Scripting

script to mail monitoring output if required or redirect output to log file

Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions. ... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

6. Shell Programming and Scripting

Mail a formatted csv file

I have the below script i am getting the csv in garbled format.Please suggest the changes. SUNOS ####################################################################### ####MAIN SCRIPT ####################################################################### today=`date "+%m-%d-%Y ... (3 Replies)
Discussion started by: rafa_fed2
3 Replies

7. UNIX for Beginners Questions & Answers

Required cpu , memory, df output in mail for multiple servers

I have prepared script which will collect cpu, memory and df out out for multiple server and send in one mail, but my script only run in one server, and when I send to mail, it shows in text format. it should be show actual format. if any one can help , that would be very grateful. script... (1 Reply)
Discussion started by: yash_message
1 Replies
GETFSSTAT(2)							System Calls Manual						      GETFSSTAT(2)

NAME
getfsstat - get list of all mounted filesystems SYNOPSIS
#include <sys/param.h> #include <sys/mount.h> int getfsstat(buf,bufsize,flags) struct statfs *buf; int bufsize; int flags; DESCRIPTION
Getfsstat() returns information about all mounted filesystems. Buf is a pointer to statfs structures defined as follows: #define MNAMELEN 90 /* length of buffer for returned name */ struct statfs { short f_type; /* type of filesystem (see below) */ short f_flags; /* copy of mount flags */ short f_bsize; /* fundamental file system block size */ short f_iosize; /* optimal transfer block size */ long f_blocks; /* total data blocks in file system */ long f_bfree; /* free blocks in fs */ long f_bavail; /* free blocks avail to non-superuser */ ino_t f_files; /* total file nodes in file system */ ino_t f_ffree; /* free file nodes in fs */ u_long f_fsid[2]; /* file system id */ long f_spare[4]; /* spare for later */ char f_mntonname[MNAMELEN]; /* mount point */ char f_mntfromname[MNAMELEN]; /* mounted filesystem */ }; /* * File system types. - Only UFS is supported so the other types are not * given. */ #define MOUNT_NONE 0 #define MOUNT_UFS 1 /* Fast Filesystem */ Fields that are undefined for a particular filesystem are set to -1. The buffer is filled with an array of fsstat structures, one for each mounted filesystem up to the size specified by bufsize. If buf is given as NULL, getfsstat() returns just the number of mounted filesystems. Normally flags is currently unused. In 4.4BSD systems the usage is specified as MNT_WAIT. If flags is set to MNT_NOWAIT, getfsstat() will return the information it has available without requesting an update from each filesystem. Thus, some of the information will be out of date, but getfsstat() will not block waiting for information from a filesystem that is unable to respond. RETURN VALUES
Upon successful completion, the number of fsstat structures is returned. Otherwise, -1 is returned and the global variable errno is set to indicate the error. ERRORS
Getfsstat() fails if one or more of the following are true: [EFAULT] Buf points to an invalid address. [EIO] An I/O error occurred while reading from or writing to the filesystem. SEE ALSO
statfs(2), fstab(5), mount(8) HISTORY
The getfsstat function first appeared in 4.4BSD. 4.4 Berkeley Distribution December 24, 1995 GETFSSTAT(2)
All times are GMT -4. The time now is 01:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy