Tooltip: Parsing (getopts) for -u successfully sets mode=umnt, but case umnt is not executed,
instead it either executes/show help or regular mount screen.
The script is ment to create a credentials file for mounting a nas, and an additional file for each share.
The creation of the config files and mounting work as it should.
However, when i want to unmount the share, it either shows the help screen (happens with none or wrong arguments) or the mount screen again.
The issue is, it doesnt seem to execute umount eventhough i passed -u and it did recognize it.
However, other arguments are executed properly...
Code:
[root@dell ~]# nas -e 192.168.10.110/Public
# | NAS Mount Helper (0.1) | #
todo edit
Some output of a set -x run while passing -u (italic in code section: Variable handling):
Code:
+ tui-title 'NAS Mount Helper (0.1)'
# | NAS Mount Helper (0.1) | #
+ '[' '!' 0 -eq 0 ']'
+ getopts edhmou: name
+ case $name in
+ doUnmount=true
+ mode=umnt
+ getopts edhmou: name
+ shift 2
And here is the code, followed by 1 successfull mount, and 2 umount tries:
[root@dell ~]# nas 192.168.10.110/Public
# | NAS Mount Helper (0.1) | #
# | Mounted Public to /mnt/nas/ [ ✔ ] | #
[root@dell ~]# nas -u 192.168.10.110/Public
# | NAS Mount Helper (0.1) | #
nas (0.1) - NAS Mount Helper
Usage: nas [options] [//]SERVERNAMEORIP/SHARENAME /local/mount/location [USERNAME PASSWORD [DOMAIN]]
Where options are:
-h This screen
-u Unmount provided nas/share/s
-d Delete provided nas/share/s
-e Edit provided nas/share/s settings
-o Overwrite provided nas/share/s settings
-m Displays a TUI/CLI menu to select from
Examples:
First time: nas //192.168.10.4/Example /mnt/examples MyName MyPassword MyDomain
Later times: nas [192.168.10.4/]Example
Delete single share: nas -d [//]192.168.10.4/Example
Delete nas configuration: nas -d [//]192.168.10.4
[root@dell ~]# nas 192.168.10.110/Public -u
# | NAS Mount Helper (0.1) | #
# | Mounting 192.168.10.110/Public to /mnt/nas/ [ ∞ ] | #
mount error(16): Device or resource busy
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
# | Mounted Public to /mnt/nas/ [ ✔ ] | #
[root@dell ~]#
Any idea why its showing the helpscreen eventhough the $mode was set to unmount (umnt)?
Thank you in advance
---------- Post updated at 16:23 ---------- Previous update was at 15:23 ----------
Its working, but not really sure why...
I removed all the OPTIND stuff, i thought that should remove the "-u" from the arglist, but neither OPTIND itself, nor OPTIND -1 helped on that matter (or i did wrong):
Code:
while getopts edhmou: name
do case $name in
e) doEdit=true
mode=edit
#shift $(($OPTIND - 1))
;;
d) doDelete=true
mode=del
;;
h) printf "$help_text"
exit $RET_HELP
;;
m) doMenu=true
mode=menu
;;
o) doOverwrite=true
mode=ow
;;
u) doUnmount=true
mode=u
#shift $(($OPTIND))
;;
?) printf "$help_text"
exit $RET_HELP
;;
esac
done
#shift $(($OPTIND - 1))
and
Code:
if [ -z $1 ] && [ ! $doMenu ] ; then
printf "$help_text"
exit $RET_HELP
elif [ $ARGS_COUNT -lt 1 ]
then printf "$help_text"
exit $RET_HELP
else if [ ! $mode = mount ]
then export SERVER=$(printf "$2"|sed s,'/',' ',g|awk '{print $1}') \
SHARE=$(printf "$2"|sed s,'/',' ',g|awk '{print $2}')
else export SERVER=$(printf "$1"|sed s,'/',' ',g|awk '{print $1}') \
SHARE=$(printf "$1"|sed s,'/',' ',g|awk '{print $2}')
fi
export CONFIG_NAS="$CONFIG_CREDS/$SERVER" \
CONFIG_SHARE="$CONFIG_SHARES/$SERVER.$SHARE"
fi
The OPTIND you removed is crucial to allow getopts() to work correctly.
But, I'm having trouble matching the arguments you're passing to getopts (edhmou: and name) with your USAGE description of your options:
Code:
Where options are:
-h This screen
-u Unmount provided nas/share/s
-d Delete provided nas/share/s
-e Edit provided nas/share/s settings
-o Overwrite provided nas/share/s settings
-m Displays a TUI/CLI menu to select from
The colon following the u in the option string argument to getopts (edhmou:) says that the -u option takes an option-argument (and the lack of a colon following the other option letters in that string says that no other options take option-arguments), but there is nothing in you code parsing the -u option:
that gathers up the option-argument that getopts will identify for you.
So, do the -d, -e, -o, and -u options (all described as performing an operation on a "provided nas/share/s") get the provided nas/share/s as an option-argument or is the nas/share/s always an operand?
Store args passed in array but not the first 2 args.
# bash
declare -a arr=("$@")
s=$(IFS=, eval 'echo "${arr}"')
echo "$s"
output:
sh array.sh 1 2 3 4 5 6
1,2,3,4,5,6
Desired output:
sh array.sh 1 2 3 4 5 6
3,4,5,6 (2 Replies)
Hello,
I have a similar problem so I continue this thread.
I have:
my_script_to_format_nicely_bdf.sh | grep "RawData" |tr -s ' '|cut -d' ' -f 4|tr -d '%'
So it supposed to return the percentage used of RawData FS:
80
(Want to use it in a alert script)
However I also have a RawData2 FS so... (17 Replies)
Hi I am executing a KSH script by passing command line arguments
example: Red Green Dark Red Blue
when I am splitting the arguments by using " "(Space) as delimiter
But the colour Dark Red is a single parameter. But it is getting splitted in between
How to avoid this. Please help Also... (4 Replies)
Hi all,
I am having problems parsing the following file:
cat mylist
one,two,three
four
five,six
My goal is to get each number on a seperate line.
one
two
three
four
five
six
I tried this command:
sed -e 's/\,/^M/g' mylist (11 Replies)
I need help with a problem that I have not been able to figure out.
I have a file that is about 650K lines. Records are seperated by
blank lines, fields seperated by new lines. I was trying to make
a report that would add up 2 fields and associate them with a CP.
example output would be... (11 Replies)
I'm trying to parse the variables out of a comma delimited expression, but i'm having trouble with script:
num_var=1
while
do
a=`echo "a=7, b=8, c=9" | awk '{print $num_var}' | cut -d= -f2`
b=`echo $a | cut -d, -f1`
echo $b
num_var=`expr $num_var + 1`... (5 Replies)