So here is what I did for this.
#!/bin/bash # This script formats and mounts all available Instance Store devices ##### Variables devices=( ) ##### Functions function add_device { devices=( "${devices[@]}" $1 ) } function check_device { if [ -e /dev/$1 ]; then add_device $1 fi } function check_devices { check_device sda2 check_device sda3 check_device sdb check_device sdc check_device sdd check_device sde } function print_devices { for device in "${devices[@]}" do echo Found device $device done } function do_mount { echo Mounting device $1 on $2 fdisk $1 << EOF n p 1 w EOF # format! mkfs -t xfs -f $1 mkdir $2 mount $1 $2 echo "$1 $2 xfs defaults 0 0" >> /etc/fstab } function mount_devices { for (( i = 0 ; i < ${#devices[@]} ; i++ )) do mountTarget=/mnt if [ $i -gt 0 ]; then mountTarget=/mnt$(($i+1)) fi do_mount /dev/${devices[$i]} $mountTarget done } ##### Main check_devices print_devices mount_devices
source share