Smart iSCSI Mounter v0.98
- Implemented quiet flag. - Reworked help display. - Re-wrote args handling to be less rigid.
This commit is contained in:
+44
-24
@@ -11,22 +11,36 @@ MONITOR_PROC_CNT=7
|
|||||||
_MONITOR_PROC_CNT=$(pgrep -f $MONITOR_PROC | wc -l)
|
_MONITOR_PROC_CNT=$(pgrep -f $MONITOR_PROC | wc -l)
|
||||||
_ISCSI_CON=""
|
_ISCSI_CON=""
|
||||||
_FLAG_FORCE=0
|
_FLAG_FORCE=0
|
||||||
|
_FLAG_QUIET=0
|
||||||
|
|
||||||
# The use of iscsiadm requires admin privilages
|
# The use of iscsiadm requires admin privilages
|
||||||
read_iscsi_con (){
|
read_iscsi_con (){
|
||||||
_ISCSI_CON=$(iscsiadm -m session)
|
_ISCSI_CON=$(iscsiadm -m session) > /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
show_usage (){
|
show_help (){
|
||||||
echo "[Usage]"
|
echo "Smart iSCSI Mounter - Help"
|
||||||
echo "Please use either '-m (--mount)' to mount or '-u (--umount)' to unmount this volume."
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Additional Options:"
|
echo "[OVERRIDE] [FUNCTION]"
|
||||||
|
echo "Example: smart-iscsi -q -m"
|
||||||
|
echo ""
|
||||||
|
echo "Overrides:"
|
||||||
|
echo "'-q (--quiet)'"
|
||||||
|
echo "'-f (--force)'"
|
||||||
|
echo ""
|
||||||
|
echo "Functions:"
|
||||||
|
echo "'-m (--mount)'"
|
||||||
|
echo "'-u (--umount)'"
|
||||||
echo "'-s (--status)'"
|
echo "'-s (--status)'"
|
||||||
echo "'-r (--release)'"
|
echo "'-r (--release)'"
|
||||||
|
echo "'-h (--help)'"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
report_status (){
|
report_status (){
|
||||||
|
if [ ${_FLAG_QUIET} == 0 ]
|
||||||
|
then
|
||||||
|
echo "[Showing status of mount-point]"
|
||||||
echo "INFO: Process '${MONITOR_PROC}' has ${_MONITOR_PROC_CNT} instances running."
|
echo "INFO: Process '${MONITOR_PROC}' has ${_MONITOR_PROC_CNT} instances running."
|
||||||
|
|
||||||
if [ $(ls $MOUNT_DIR/. | wc -l) -ge 1 ]
|
if [ $(ls $MOUNT_DIR/. | wc -l) -ge 1 ]
|
||||||
@@ -42,6 +56,7 @@ report_status (){
|
|||||||
echo ""
|
echo ""
|
||||||
echo "There is/are currently '$(${_ISCSI_CON} 2>&1 | wc -l)' iSCSI connection(s) open:"
|
echo "There is/are currently '$(${_ISCSI_CON} 2>&1 | wc -l)' iSCSI connection(s) open:"
|
||||||
echo "${_ISCSI_CON}"
|
echo "${_ISCSI_CON}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_proc_status (){
|
check_proc_status (){
|
||||||
@@ -50,28 +65,37 @@ check_proc_status (){
|
|||||||
echo "WARNING: process '${MONITOR_PROC}' is still running, unable to unmount volume safely."
|
echo "WARNING: process '${MONITOR_PROC}' is still running, unable to unmount volume safely."
|
||||||
exit 2;
|
exit 2;
|
||||||
else
|
else
|
||||||
|
if [ ${_FLAG_QUIET} == 0 ]
|
||||||
|
then
|
||||||
echo "INFO: Process ${MONITOR_PROC} is not running."
|
echo "INFO: Process ${MONITOR_PROC} is not running."
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
mount_func (){
|
mount_func (){
|
||||||
|
if [ ${_FLAG_QUIET} == 0 ]
|
||||||
|
then
|
||||||
echo "[Attempting to mount iSCSI volume]"
|
echo "[Attempting to mount iSCSI volume]"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ${_ISCSI_CON} == *${IQN}* ]] && [[ $_FLAG_FORCE -eq 0 ]]
|
if [[ ${_ISCSI_CON} == *${IQN}* ]] && [[ $_FLAG_FORCE -eq 0 ]]
|
||||||
then
|
then
|
||||||
|
echo ""
|
||||||
echo "WARNING: You're already connected to the '${IQN}' iSCSI target."
|
echo "WARNING: You're already connected to the '${IQN}' iSCSI target."
|
||||||
echo "Use the -f (--force) flag to bypass this warning."
|
echo "Use the -f (--force) flag to bypass this warning."
|
||||||
exit 2;
|
exit 2;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
iscsiadm --mode node --targetname $IQN --portal $PORTAL_IP --login
|
iscsiadm --mode node --targetname $IQN --portal $PORTAL_IP --login > /dev/null 2>&1
|
||||||
sleep 3
|
sleep 3
|
||||||
mount /dev/disk/by-uuid/$DISK_UUID $MOUNT_DIR -o noauto,noperm
|
mount /dev/disk/by-uuid/$DISK_UUID $MOUNT_DIR -o noauto,noperm > /dev/null 2>&1
|
||||||
report_status
|
|
||||||
}
|
}
|
||||||
|
|
||||||
umount_func (){
|
umount_func (){
|
||||||
|
if [ ${_FLAG_QUIET} == 0 ]
|
||||||
|
then
|
||||||
echo "[Attempting to un-mount iSCSI volume]"
|
echo "[Attempting to un-mount iSCSI volume]"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $_FLAG_FORCE -eq 0 ]]; then
|
if [[ $_FLAG_FORCE -eq 0 ]]; then
|
||||||
check_proc_status
|
check_proc_status
|
||||||
@@ -79,15 +103,15 @@ umount_func (){
|
|||||||
|
|
||||||
if [[ ${_ISCSI_CON} != *${IQN}* ]] && [[ $_FLAG_FORCE -eq 0 ]]
|
if [[ ${_ISCSI_CON} != *${IQN}* ]] && [[ $_FLAG_FORCE -eq 0 ]]
|
||||||
then
|
then
|
||||||
|
echo ""
|
||||||
echo "WARNING: You're not currently connected to the '${IQN}' iSCSI target."
|
echo "WARNING: You're not currently connected to the '${IQN}' iSCSI target."
|
||||||
echo "Use the -f (--force) flag to bypass this warning."
|
echo "Use the -f (--force) flag to bypass this warning."
|
||||||
exit 2;
|
exit 2;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
umount -l $MOUNT_DIR
|
umount -l $MOUNT_DIR > /dev/null 2>&1
|
||||||
sleep 3
|
sleep 3
|
||||||
iscsiadm --mode node --targetname $IQN --portal $PORTAL_IP --logout
|
iscsiadm --mode node --targetname $IQN --portal $PORTAL_IP --logout > /dev/null 2>&1
|
||||||
report_status
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_admin (){
|
check_admin (){
|
||||||
@@ -101,6 +125,11 @@ check_admin (){
|
|||||||
# Process input parameters
|
# Process input parameters
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
|
-q|--quiet)
|
||||||
|
read_iscsi_con
|
||||||
|
_FLAG_QUIET=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-f|--force)
|
-f|--force)
|
||||||
_FLAG_FORCE=1
|
_FLAG_FORCE=1
|
||||||
shift
|
shift
|
||||||
@@ -109,40 +138,31 @@ for arg in "$@"; do
|
|||||||
check_admin
|
check_admin
|
||||||
read_iscsi_con
|
read_iscsi_con
|
||||||
mount_func
|
mount_func
|
||||||
|
report_status
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-u|--umount)
|
-u|--umount)
|
||||||
check_admin
|
check_admin
|
||||||
read_iscsi_con
|
read_iscsi_con
|
||||||
umount_func
|
umount_func
|
||||||
|
report_status
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-s|--status)
|
-s|--status)
|
||||||
echo "[Showing status of mount-point]"
|
|
||||||
check_admin
|
check_admin
|
||||||
read_iscsi_con
|
read_iscsi_con
|
||||||
report_status
|
report_status
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-r|--release)
|
-r|--release)
|
||||||
echo "Smart iSCSI Mounter v0.97.1"
|
echo "Smart iSCSI Mounter v0.98"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-h|--help)
|
-h|--help)
|
||||||
show_usage
|
show_help
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-q|--quiet)
|
|
||||||
echo "Quiet"
|
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Show usage if no parameters have been passed
|
|
||||||
if [[ $# -eq 0 ]]
|
|
||||||
then
|
|
||||||
show_usage
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit 0;
|
exit 0;
|
||||||
Reference in New Issue
Block a user