Initial script to mount and unmount iSCSI shares

This commit is contained in:
2020-05-20 14:14:51 +01:00
parent 5cdaf07025
commit b7151c57c6
Executable
+59
View File
@@ -0,0 +1,59 @@
#!/bin/bash
DISK_UUID="12E6B87AE6B86021"
IQN="iqn.2000-01.com.synology:SR3.VMs"
PORTAL_IP="192.168.0.3"
MOUNT_DIR="/home/dunestorm/VMs"
show_usage (){
echo "Please use either '-m (--mount)' to mount or '-u (--umount)' to unmount this volume."
exit 1;
}
check_dir (){
file_count=$(ls $MOUNT_DIR/. | wc -l)
if [ "$file_count" -ge 1 ]
then
echo ""
echo "Directory has been mounted at:" $MOUNT_DIR
else
echo ""
echo "Directory has been un-mounted from:" $MOUNT_DIR
fi
}
# Check for admin rights
if [[ $EUID -ne 0 ]]
then
echo "You may only mount as root, please re-run with appropriate permissions."
exit 1;
fi
# Process input parameters
while (( "$#" )); do
case "$1" in
-m|--mount)
iscsiadm --mode node --targetname $IQN --portal $PORTAL_IP --login
sleep 3
mount /dev/disk/by-uuid/$DISK_UUID $MOUNT_DIR
check_dir
exit 0;
;;
-u|--umount)
umount $MOUNT_DIR
iscsiadm --mode node --targetname $IQN --portal $PORTAL_IP --logout
check_dir
exit 0;
;;
-*)
show_usage
;;
esac
done
# Show usage if no parameters have been passed
if [[ $# -eq 0 ]]
then
show_usage
fi