CentOS7LVM logical partition automatic expansion Shell Scripting

Scenarios and known issues:
Apply to CentOS6 or CentOS7 (possibly available on CentOS4 and earlier versions such as 5)
The root file system (extended file system) use LVM to manage, such as the mount command output /dev/mapper/vg_$hostname-lv_root on/type ext4 (RW) in the Mapper keywords
Automatic expansion of the root file system, if you want to expand to other file systems, such as the existing business application data directory is not in the root partition, you will need to modify the VG_PATH_TO_EXTEND variable in the Shell script code (around line 78).
Only support partition formats such as ext2, ext3, ext4, XFS file systems
May not support some customized CentOS system, but the core steps similar to
Scripts only add SCSI disk support, such as the need to manage other disks, you need to expand their own scripts
To keep the script simple, avoiding multiple (implementation of this program does not write locks), pre-existing disk name is already set for the SDA, see ONLINE_SCSI_DISK_PRESENT 45th row variable in Shell script code
Considerations:
CentOS6 and CentOS7 in the file system format of the default root file system differences, needs to determine whether the XFS, if XFS xfs_growfs option should be used instead of using the resize2fs.
Using the resize2fs extension of ext2, ext3, ext4 file system, use the xfs_growfs expanding XFS file system format
The same script is executed multiple times on the same system error that might be thrown, you can consider the use of file locking to solve this problem
Programming method:
(Should be prepared or checked before Shell Script Runtime Environment) for block device file names currently in use
Get new add SCSI disk filename
Gets a LVM volume group (VG), the file path of the volume group name will be expanded
To add a new disk using Fdisk partition is created and formatted with the LVM format
Create a physical volume, pvcreate
Extending a volume group, vgextend
Regulate the logical volume size, lvresize
Determine whether the XFS file system
Synchronize file systems, making expansion effect
Returns the system disk usage
Shell code: