Skip to content

Instantly share code, notes, and snippets.

@marinnedea
Last active June 19, 2018 13:39
Show Gist options
  • Save marinnedea/8de92000e63264a458176672a49dbf28 to your computer and use it in GitHub Desktop.
Save marinnedea/8de92000e63264a458176672a49dbf28 to your computer and use it in GitHub Desktop.
# !/usr/bin/env bash
# Setting the logfile location
logfile=/var/log/mount_disks.log
# Logging all actions
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>$logfile 2>&1
# Logging the start date and time
date +"%F_%R"
# Create an array with the data disks UUIDs and fstype
declare -a datadisksarr="$(blkid | awk -F '"' '!/\/(\*|sda|sdb)/{ print $2" "$4}')"
# Iterate through each line of the array
printf '%s\n' "${datadisksarr[*]}" | while ((i++)); read -r line; do
#echo "$i $line"
UUID="$(echo $line | awk '{print $1}')"
fstype="$(echo $line | awk '{print $2}')"
#echo "UUID is: $UUID";
#echo "FSType is: $fstype";
grep "$UUID" /etc/fstab >/dev/null 2>&1
if [ ${?} -eq 0 ];
then
echo "Not adding $UUID to fstab again (it's already there!)"
else
# Create the mountpoint
mkdir -p /datadisk$i
# Add the UUID to /etc/fstab
echo -e "UUID=$UUID /datadisk$i $fstype defaults,nofail 0 2 " >> /etc/fstab
fi
done
# Mount everything listed in /fstab
mount -a
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment