Forum › Forums › antiX-development › Development › disconnectshares more flexible
Tagged: typo
- This topic has 6 replies, 4 voices, and was last updated Oct 27-7:04 am by Robin.
-
AuthorPosts
-
October 26, 2020 at 1:19 am #43778Member
Robin
Hello people,
I was just configuring and fine-tuning antiX on my laptop and came across the disconnectshares-script, which asked me constantly to check the boxes again and again, which share(s) was(were) to be unmounted. Since the shares are connected via WLAN, it is obvious that ALL shares have to be unmounted. Every single time I log out from the server. This is quite – let me say – time-consuming and much clickwork. So I decided to add some lines in the script, making things easier for me and more flexible.
I’ll post the slightly complemented script here in case it is usefull to somebody. I want to give back something, even if it is a small piece only, to the antiX community, for what you gave to me with this great OS. I am not a programmer, but have studied the basics of FORTRAN F77 some decades ago, and had some experience in BASIC, MS-DOS scripting, AutoLISP (AutoCAD), the first EXCEL-Macro-Language. It’s long time ago I last used these skills, so my output might not be exactly what one would call elegant coding. Sorry for that. But it works, at least for me.Functionality I added:
– works without need to check every box, when all shares are to be unmounted (eg. for the Wireless Connection has to be powered off.); commandline-switch: “-a”
– ability to work without pop-up boxes, when all shares are unmounted, (since I’ll try to make it show its status in system-tray if its not too difficult for me and it isnt to ressource-hungry); commandline-swich: “-s”
– Aditional Message, when nothing was to unmount instead of no information or failur-message.My Idea is it to add another switch, “-f <filename>”, to read data from a predefined config-file, which mounts are to be unmounted.
Here is what it is until now:
#! /bin/sh PROGNAME=${0##*/} PROGVERSION="7.0" # -------------------- # Help and Information # -------------------- # Test for a help request if [ "$1" = '-h' ] || [ "$1" = '--help' ]; then cat << end-of-messageblock $PROGNAME version $PROGVERSION Unmount remote shares from the local system Usage: $PROGNAME [options] Options: -h, --help Show this output -a, --all Disconnect all shares -s, --silent Disconnect all shares without dialogboxes. Summary: Remote CIFS and NFS shares that are mounted on to the local file system are presented in an interactive menu. From the menu, one or more shares may be selected and unmounted. A report file summarizing the outcome is produced in /tmp. Requires: awk, cat, cut, grep, dialog, mktemp, sed, sync, umount Documentation: http://invisible-island.net/dialog See also: connectshares connectshares.sh connectshares-config connectshares-config.sh disconnectshares end-of-messageblock exit 0 fi # ------------------------------------------------------------- # store decision whether user wants all shares to be unmounted # ------------------------------------------------------------- ALLSHARES=0 if [ "$1" = '-a' ] || [ "$1" = '--all' ]; then ALLSHARES=1; fi # ---------------------------------------------------------------------- # store decision whether user wants all shares to be unmounted silently # this includes ALLSHARES flag to be set also. # ---------------------------------------------------------------------- SILENT=0 if [ "$1" = '-s' ] || [ "$1" = '--silent' ]; then ALLSHARES=1 SILENT=1 fi # ---------------------- # Verify user privileges # ---------------------- # When not run via sudo display an error message if [ -z "$SUDO_USER" ];then dialog --title "Error" \ --no-shadow \ --ok-label "Exit" \ --msgbox "\ndisconnectshares.sh requires root privileges. \nIt should be run via sudo. \n " \ 15 50 clear exit 1 fi # ------------- # Set Variables # ------------- # File to hold transient output TEMPFILE1=$(mktemp -q) || TEMPFILE1=/tmp/tempfile1$$ # Save the default IFS value then set IFS value to a comma IFSDEFAULT=$IFS IFS=, # Check, whether user wants all shares unmounted if [ "$ALLSHARES" = 0 ]; then # --------- # Main Menu # --------- # Create a comma separated list of remote share names mounted on the local system { grep -E 'cifs|nfs' /etc/mtab | \ awk '/\/mnt\// { print $2 }' | \ awk -F / '{ print $4 }' | \ sed 's/$/,/;s/\\040/ /g' > $TEMPFILE1 } # Create vars for dialog checklist parameters tag, item, status, for each share name COUNTER=1 # Note: while loop data input at end of do/done while read SHARENAME do case $COUNTER in 1) TAG1=$COUNTER && ITEM1=$SHARENAME && STATUS1=off ;; 2) TAG2=$COUNTER && ITEM2=$SHARENAME && STATUS2=off ;; 3) TAG3=$COUNTER && ITEM3=$SHARENAME && STATUS3=off ;; 4) TAG4=$COUNTER && ITEM4=$SHARENAME && STATUS4=off ;; 5) TAG5=$COUNTER && ITEM5=$SHARENAME && STATUS5=off ;; 6) TAG6=$COUNTER && ITEM6=$SHARENAME && STATUS6=off ;; 7) TAG7=$COUNTER && ITEM7=$SHARENAME && STATUS7=off ;; 8) TAG8=$COUNTER && ITEM8=$SHARENAME && STATUS8=off ;; 9) TAG9=$COUNTER && ITEM9=$SHARENAME && STATUS9=off ;; 10) TAG10=$COUNTER && ITEM10=$SHARENAME && STATUS10=off ;; esac COUNTER=$(expr $COUNTER + 1) done < $TEMPFILE1 # Display the interactive menu of share names available for unmounting #+ and create a list of shares tagged for unmounting dialog --title "[Arrows] move up/down [Spacebar] mark for disconnection" \ --no-shadow \ --separate-output \ --checklist "" 20 70 20 \ $TAG1 $ITEM1 $STATUS1 \ $TAG2 $ITEM2 $STATUS2 \ $TAG3 $ITEM3 $STATUS3 \ $TAG4 $ITEM4 $STATUS4 \ $TAG5 $ITEM5 $STATUS5 \ $TAG6 $ITEM6 $STATUS6 \ $TAG7 $ITEM7 $STATUS7 \ $TAG8 $ITEM8 $STATUS8 \ $TAG9 $ITEM9 $STATUS9 \ $TAG10 $ITEM10 $STATUS10 \ 2> $TEMPFILE1 # Check if user selected cancel button or closed the window [ "$?" != 0 ] && clear && rm $TEMPFILE1 && exit 1 # Transfer values and empty temporary file TAGGED=$(cat $TEMPFILE1) cat /dev/null > $TEMPFILE1 # -------------------------------------- # Correlate tagged shares to mountpoints # -------------------------------------- # Create a numbered, comma separated list of mountpoints of shares currently mounted { MOUNTED=$(grep -E 'cifs|nfs' /etc/mtab | \ awk '/\/mnt\// { print $2 }' | \ sed = | sed 'N;s/\n/ /;s/$/,/;s/\\040/ /g') } # Create a list of mountpoints corresponding to the tagged shares echo "$TAGGED" | while read TAGGEDLINE do echo "$MOUNTED" | while read MOUNTEDLINE do if [ "$TAGGEDLINE" = $(echo "$MOUNTEDLINE" | cut -d " " -f 1) ]; then echo "$(echo "$MOUNTEDLINE" | cut -d " " -f 2-)" >> $TEMPFILE1 fi done done else # Empty temporary file, just to be sure cat /dev/null > $TEMPFILE1 # ------------------------------------ # Correlate ALL shares to mountpoints # ------------------------------------ # Create a numbered, comma separated list of mountpoints of shares currently mounted { MOUNTED=$(grep -E 'cifs|nfs' /etc/mtab | \ awk '/\/mnt\// { print $2 }' | \ sed = | sed 'N;s/\n/ /;s/$/,/;s/\\040/ /g') } # Create a list of mountpoints of all shares echo "$MOUNTED" | while read MOUNTEDLINE do echo "$(echo "$MOUNTEDLINE" | cut -d " " -f 2-)" >> $TEMPFILE1 done fi # Transfer values and empty temporary file MOUNTPOINTLIST=$(cat $TEMPFILE1) cat /dev/null > $TEMPFILE1 # If there is nothing to unmount, don't try it. if [ -z "$MOUNTPOINTLIST" ]; then echo "Nothing to do." >> $TEMPFILE1 # in case user wants to be informed # clear && rm $TEMPFILE1 && exit 1 # in style like the original script did it else # ---------- # Disconnect # ---------- # Unmount the tagged shares, and set a status indicator sync echo "$MOUNTPOINTLIST" | while read MOUNTPOINT do umount -f $MOUNTPOINT ERRORCODE="$?" # Store the status of the unmount attempt [ "$ERRORCODE" = 0 ] && echo "Success unmounting $(echo $MOUNTPOINT | cut -d "/" -f 4-)" >> $TEMPFILE1 [ "$ERRORCODE" != 0 ] && echo "Failure unmounting $(echo $MOUNTPOINT | cut -d "/" -f 4-)" >> $TEMPFILE1 done fi # ----------------------------------------- # Summarize the status of unmounting shares # ----------------------------------------- #Check whether user wants to see this if [ "$SILENT" = 0 ]; then # Display the summary dialog --title "Summary" \ --no-shadow \ --sleep 5 \ --cr-wrap \ --infobox "\n$(cat $TEMPFILE1) \n " \ 20 70 else #in case script was called from commandline and user wants to be informed cat $TEMPFILE1 fi # Save the summary report cat $TEMPFILE1 > /tmp/disconnectshares.rpt # -------- # Clean up # -------- # Delete the temporary file rm $TEMPFILE1 # ----- # Close # ----- #clear screen (only if there is something to clear) if [ "$SILENT" = 0 ]; then clear; fi exit 0Greetings
RobinP.S.: Original Script was taken from antiX 17.4.1, recently updated with ‘apt-get upgrade’.
- This topic was modified 2 years, 6 months ago by Robin. Reason: orthography
- This topic was modified 2 years, 6 months ago by Robin. Reason: orthography
Windows is like a submarine. Open a window and serious problems will start.
October 26, 2020 at 4:54 am #43782MemberRobin
::OK, here is my next version, implementing the reading of shares to be unmounted from a file. Each share has to be written on its own line, there mustn’t be used any seperators or apostrophes in the file. No input-checks are performed, so it is crucial not to mess up filenames and mountpoints when using it. These input-testing should be added at some point for safety of our users. The original functionality of the script (without any commandline-switches) is still untouched, it works as before. I’ve tested its function in antix 17.4.1 with all recent updates (kernel: 4.9.240-antix.1-686-smp-pae).
#! /bin/sh PROGNAME=${0##*/} PROGVERSION="7.0" # -------------------- # Help and Information # -------------------- # Test for a help request if [ "$1" = '-h' ] || [ "$1" = '--help' ]; then cat << end-of-messageblock $PROGNAME version $PROGVERSION Unmount remote shares from the local system Usage: $PROGNAME [options] Options: -h, --help Show this output. -a, --all Disconnect all shares. -sa, --silent Disconnect all shares without dialogboxes. -f, --file <filename> Use configfile instead of interactive dialog. -sf combination of -s and -f Summary: Remote CIFS and NFS shares that are mounted on to the local file system are presented in an interactive menu. From the menu, one or more shares may be selected and unmounted. A report file summarizing the outcome is produced in /tmp. Commandline-switches: -a disconnects _all_ mounted CIFS and NFS shares and confirms action afterwards in a pop-up-dialog. -sa does the same, without any dialog. Mainly for use in connection with other ways of status-display (e.g.taskbar) when called from the commandline it will write the messages there. -f reads list of shares to be unmounted from a given configuration file. The filename may contain the path. Each mount is to be written on a single line, with its full path. e.g. /mnt/antiX2/MyFolder /mnt/antix4/Music -sf means, it shows not even the summary-message in the end, apart from that is functions identical as the -f switch. Requires: awk, cat, cut, grep, dialog, mktemp, sed, sync, umount Documentation: http://invisible-island.net/dialog See also: connectshares connectshares.sh connectshares-config connectshares-config.sh disconnectshares end-of-messageblock exit 0 fi # ------------------------------------------------------------- # store decision whether user wants all shares to be unmounted # ------------------------------------------------------------- ALLSHARES=0 if [ "$1" = '-a' ] || [ "$1" = '--all' ]; then ALLSHARES=1; fi # ---------------------------------------------------------------------- # store decision whether user wants all shares to be unmounted silently # this includes ALLSHARES flag to be set also. # ---------------------------------------------------------------------- SILENT=0 if [ "$1" = '-sa' ] || [ "$1" = '--silent' ]; then ALLSHARES=1 SILENT=1 fi # ------------------------------------------------------------- # store decision whether user wants to read from config-file # and all shares to be unmounted # ------------------------------------------------------------- FROMFILE=0 if [ "$1" = '-f' ] || [ "$1" = '-sf' ] || [ "$1" = '--file' ]; then FROMFILE=1 ALLSHARES=1 if [ "$1" = '-sf' ]; then SILENT=1; fi CFGFILE="$2" # todo: here should be done some input-checking with the # content of the variable CFGFILE, before using it. echo "reading shares to unmount from "$CFGFILE" ..." fi # ---------------------- # Verify user privileges # ---------------------- # When not run via sudo display an error message if [ -z "$SUDO_USER" ];then dialog --title "Error" \ --no-shadow \ --ok-label "Exit" \ --msgbox "\ndisconnectshares.sh requires root privileges. \nIt should be run via sudo. \n " \ 15 50 clear exit 1 fi # ------------- # Set Variables # ------------- # File to hold transient output TEMPFILE1=$(mktemp -q) || TEMPFILE1=/tmp/tempfile1$$ # Save the default IFS value then set IFS value to a comma IFSDEFAULT=$IFS IFS=, E_NOFILE=86 #--------------------------------------- # Check if cfg-file exists, if requested #--------------------------------------- if [ "$FROMFILE" = 1 ]; then if [ ! -f "$CFGFILE" ]; then echo "File \"$CFGFILE\" does not exist." rm $TEMPFILE1 && exit $E_NOFILE fi fi # Check, whether user wants all shares unmounted if [ "$ALLSHARES" = 0 ]; then # --------- # Main Menu # --------- # Create a comma separated list of remote share names mounted on the local system { grep -E 'cifs|nfs' /etc/mtab | \ awk '/\/mnt\// { print $2 }' | \ awk -F / '{ print $4 }' | \ sed 's/$/,/;s/\\040/ /g' > $TEMPFILE1 } # Create vars for dialog checklist parameters tag, item, status, for each share name COUNTER=1 # Note: while loop data input at end of do/done while read SHARENAME do case $COUNTER in 1) TAG1=$COUNTER && ITEM1=$SHARENAME && STATUS1=off ;; 2) TAG2=$COUNTER && ITEM2=$SHARENAME && STATUS2=off ;; 3) TAG3=$COUNTER && ITEM3=$SHARENAME && STATUS3=off ;; 4) TAG4=$COUNTER && ITEM4=$SHARENAME && STATUS4=off ;; 5) TAG5=$COUNTER && ITEM5=$SHARENAME && STATUS5=off ;; 6) TAG6=$COUNTER && ITEM6=$SHARENAME && STATUS6=off ;; 7) TAG7=$COUNTER && ITEM7=$SHARENAME && STATUS7=off ;; 8) TAG8=$COUNTER && ITEM8=$SHARENAME && STATUS8=off ;; 9) TAG9=$COUNTER && ITEM9=$SHARENAME && STATUS9=off ;; 10) TAG10=$COUNTER && ITEM10=$SHARENAME && STATUS10=off ;; esac COUNTER=$(expr $COUNTER + 1) done < $TEMPFILE1 # Display the interactive menu of share names available for unmounting #+ and create a list of shares tagged for unmounting dialog --title "[Arrows] move up/down [Spacebar] mark for disconnection" \ --no-shadow \ --separate-output \ --checklist "" 20 70 20 \ $TAG1 $ITEM1 $STATUS1 \ $TAG2 $ITEM2 $STATUS2 \ $TAG3 $ITEM3 $STATUS3 \ $TAG4 $ITEM4 $STATUS4 \ $TAG5 $ITEM5 $STATUS5 \ $TAG6 $ITEM6 $STATUS6 \ $TAG7 $ITEM7 $STATUS7 \ $TAG8 $ITEM8 $STATUS8 \ $TAG9 $ITEM9 $STATUS9 \ $TAG10 $ITEM10 $STATUS10 \ 2> $TEMPFILE1 # Check if user selected cancel button or closed the window [ "$?" != 0 ] && clear && rm $TEMPFILE1 && exit 1 # Transfer values and empty temporary file TAGGED=$(cat $TEMPFILE1) cat /dev/null > $TEMPFILE1 # -------------------------------------- # Correlate tagged shares to mountpoints # -------------------------------------- # Create a numbered, comma separated list of mountpoints of shares currently mounted { MOUNTED=$(grep -E 'cifs|nfs' /etc/mtab | \ awk '/\/mnt\// { print $2 }' | \ sed = | sed 'N;s/\n/ /;s/$/,/;s/\\040/ /g') } # Create a list of mountpoints corresponding to the tagged shares echo "$TAGGED" | while read TAGGEDLINE do echo "$MOUNTED" | while read MOUNTEDLINE do if [ "$TAGGEDLINE" = $(echo "$MOUNTEDLINE" | cut -d " " -f 1) ]; then echo "$(echo "$MOUNTEDLINE" | cut -d " " -f 2-)" >> $TEMPFILE1 fi done done else # Empty temporary file, just to be sure cat /dev/null > $TEMPFILE1 # check if user has given a config-file if [ "$FROMFILE" = 1 ]; then # --------------------------- # read from given config file # --------------------------- cut -z --output-delimiter="," -d' ' -f 1- $CFGFILE > $TEMPFILE1 # todo: here should be a check whether the file content isn't garbage else # ------------------------------------ # Correlate ALL shares to mountpoints # ------------------------------------ echo "looking for mounted shares..." # Create a numbered, comma separated list of mountpoints of shares currently mounted { MOUNTED=$(grep -E 'cifs|nfs' /etc/mtab | \ awk '/\/mnt\// { print $2 }' | \ sed = | sed 'N;s/\n/ /;s/$/,/;s/\\040/ /g') } # Create a list of mountpoints of all shares echo "$MOUNTED" | while read MOUNTEDLINE do echo "$(echo "$MOUNTEDLINE" | cut -d " " -f 2-)" >> $TEMPFILE1 done fi fi # in any case, at this point we have a valid content of $TEMPFILE1. # Transfer values and empty temporary file MOUNTPOINTLIST=$(cat $TEMPFILE1) cat /dev/null > $TEMPFILE1 # If there is nothing to unmount, don't try it. if [ -z "$MOUNTPOINTLIST" ]; then echo "Nothing to do." >> $TEMPFILE1 # in case user wants to be informed # clear && rm $TEMPFILE1 && exit 1 # in style like the original script did it else # ---------- # Disconnect # ---------- # Unmount the tagged shares, and set a status indicator sync echo "$MOUNTPOINTLIST" | while read MOUNTPOINT do umount -f $MOUNTPOINT ERRORCODE="$?" # Store the status of the unmount attempt [ "$ERRORCODE" = 0 ] && echo "Success unmounting $(echo $MOUNTPOINT | cut -d "/" -f 4-)" >> $TEMPFILE1 [ "$ERRORCODE" != 0 ] && echo "Failure unmounting $(echo $MOUNTPOINT | cut -d "/" -f 4-)" >> $TEMPFILE1 done fi # ----------------------------------------- # Summarize the status of unmounting shares # ----------------------------------------- #Check whether user wants to see this if [ "$SILENT" = 0 ]; then # Display the summary dialog --title "Summary" \ --no-shadow \ --sleep 5 \ --cr-wrap \ --infobox "\n$(cat $TEMPFILE1) \n " \ 20 70 else #in case script was called from commandline and user wants to be informed cat $TEMPFILE1 fi # Save the summary report cat $TEMPFILE1 > /tmp/disconnectshares.rpt # -------- # Clean up # -------- # Delete the temporary file rm $TEMPFILE1 # ----- # Close # ----- #clear screen (only if there is something to clear) if [ "$SILENT" = 0 ]; then clear; fi exit 0Have fun with it,
RobinXxx edited by bobc
- This reply was modified 2 years, 6 months ago by BobC. Reason: Try to fix
Windows is like a submarine. Open a window and serious problems will start.
October 26, 2020 at 6:43 am #43785ModeratorBobC
October 26, 2020 at 12:53 pm #43804Memberolsztyn
::I was just configuring and fine-tuning antiX on my laptop and came across the disconnectshares-script, which asked me constantly to check the boxes again and again, which share(s) was(were) to be unmounted. Since the shares are connected via WLAN, it is obvious that ALL shares have to be unmounted. Every single time I log out from the server. This is quite – let me say – time-consuming and much clickwork. So I decided to add some lines in the script, making things easier for me and more flexible.
I am just an average user of Connectshares, not a programmer, so I am curious of how this script is applied in practice. Does it need to be invoked from a command line?
So far I have been connecting SMB shares using Connectshares when needed and either disconnecting manually through Disconnectshares or at laptops shutdown. If multiple shares are connected then Disconnectshares requires to check which are to be disconnected.
As I understand your script disconnects all SMB shares of of the entire server in one shot?
Thanks and Regards…Live antiX Boot Options (Previously posted by Xecure):
https://antixlinuxfan.miraheze.org/wiki/Table_of_antiX_Boot_ParametersOctober 26, 2020 at 3:27 pm #43821Forum AdminSamK
::Since the shares are connected via WLAN, it is obvious that ALL shares have to be unmounted.
It is disputable that “it is obvious that all shares have to be unmounted” simply because you use wlan.
By design Connectshares is able to mount a single or multiple remote resources, on a single or multiple remote servers, using different protocols. It can do this individually (manually) or as a group (automatically) making resources available from one or more servers on one or more machines in the LAN.
The popular way to provide access to frequently used resources is to automatically mount them at system startup via the user session startup file. They are usually needed throughout the session. Additional resources can be mounted on demand irrespective of whether they orginate from the same server.
Disconnectshares is able to unmount a single or multiple shares on demand (manually) irrespective of their remote origin.
The usual way to unmount the frequently used shares that are needed throughout the session is as a group (automatically) at shutdown.
Every single time I log out from the server.
If “log out from the server” means unmount a remote share(s) the easiest method is to unmount all resources automatically as a group when the local client system is shut down.
October 26, 2020 at 3:59 pm #43822Forum AdminSamK
::As I understand your script disconnects all SMB shares of of the entire server in one shot?
Thanks and Regards…No. It will only disconnect remote resources mounted by the method which Disonnectshares employs as previously described.
…if SMB shares have been connected via methods other than Connectshares then Disconnectshares does not seem to detect any shares as connected in order to disconnect…
Because of the many different ways of connecting to shares it is not feasible to have a single way to deal with gracefully breaking all connections. For that reason each method of connecting usually provides its own method of disconnecting.
- This reply was modified 2 years, 6 months ago by SamK.
- This reply was modified 2 years, 6 months ago by SamK.
- This reply was modified 2 years, 6 months ago by SamK.
October 27, 2020 at 7:04 am #43858MemberRobin
::so I am curious of how this script is applied in practice. Does it need to be invoked from a command line?
Well, let me say first, many things in our OS are regulated and executed by scripts of that kind. The normal user won’t even notice it was a script which did something automatically. This is true for this script also. From the perspective of the user it appears just as an entry in a menu or as a checkbox in a configuration utility. The creators of the OS arrange things in a way, he – the user – doesn’t have to think about every single routine job his computer executes, after he has set some checkboxes in the very beginning. The experienced user may tinker with the advanced option most scripts (and also real programs) provide.
If you use the connectshares/disconnectshares-entry in Menu–>Aplications–>Internet–>Connectshares or Disconnectshares, then you actually start exactly that script. It bings the grey window with its checkbox(es) on your screen, where you can chose which share is to be disconnected, in more technical terms: unmounted. You can try yourself, if you are starting connectshares/disconnectshares from the menu usually (having configured it already) you can open a virtual console (Terminal-Window) on your antiX-System, type in first connectshares, and see what happens. Then type in disconnectshares. And finally type disconnectshares –help in order to understand, what’s really going on behind the scenes. You will get a help-message in the terminalwindow, mostly identic to that you can read above in the first few codelines of my version of the script. Actually it is that text, slightly complemented. Also you could type in a terminal-window: cat /usr/local/bin/connectshares.sh, which will print out that very script script in its original form on your terminal-window, as it is used already in your antiX-system.
What I did, was to add some features to the original script. In the first place, it works exactly as before, if you don’t give any option (commandline-switch) when starting. This is the normal use-case, as before.And now, what are the additional switches good for in my version? Well, there are some use-cases, or scenarios:
If you have always only one connection to a single share, i.e., your 2nd pc in the coal-cellar, runing samba, it is a useless question which share should be unmounted every day. Always you will click on that box, just because it is there, seven day’s a week. I asked me whether the script had a built-in option to disconnect a share without bothering me with this routine task. connectshares -h told me, there was no option at all.Now let us discuss the question, in which scenarios (use-cases) it would be mandatory to disconnect shares. May be I’ve missunderstood the concept of connectshares, but in my perspective it should be used always before the connection to the server(s) is cut.
This will happen
– on shutdown. Here does an other mechanism do the job, I think (haven’t checked).
– on suspend-to-ram. I noticed that recover from suspend fails siginficantly more often when shares are not disconnected before. I don’t know the reason, but I observed it in 17.4.1 recently apt-upgraded and when using noveau-driver instead of nvidia-legacy. What is the connection between, I can’t tell. But I have always to use disconnectshares before suspending to ram. And here is a script, which has no option to automatize the job, disconnecting (and connecting again after resume) the shares which were actually mounted. And, doing its job, not to bother the user with unnecessery questions. That’s the idea behind the switches I added to the scipt. The script with options is intended to be called from other scripts, that are responsible for the execution of the suspension, in our case it would be desktop-session-exit -S probably. May be, it turns out the options I added are not sufficient and have to be supplemented or adjusted later on.
– on hibernating. The before said is true here also. Keep in mind, we have notebooks which can be suspended or hibernated instead of shut down, carried away in this state and then there possibly won’t be a server to disconnect from after resuming. Then it is better I think, when the shares are disconnected already beforehand, the user will not miss them after resuming, very well knowing he is at another location. When he stays in reach of his WLAN (and his share-server) the scripting will do the reconnect to the shares silently on resume (Well here is some scripting left to be done).
– at one keystroke of the user, when he is going to leave a location with running equipment tucked under his arm for some reason.
– Since the new options allow to hand over a filename, you’ll be able to connect and disconnect a predeterminded set of shares depending on the location you are with your notebook mostly automatically. You could create menuentries (e.g. “At home”, “At University”, “At Grandma” …) each with a different set of shares to be connected _and_ disconnected from. Connectshares already has the ability to handle different config-files, but disconnectshares didn’t. We always to had to check the boxes instead of using a predetermined set of files (configfiles of connectshares i.e.).The usual way to unmount the frequently used shares that are needed throughout the session is as a group (automatically) at shutdown.
Think twice. As I stated above, we talk about notebooks also, so you might not shut the computer down necessarily, before carrying it away. Maybe it is hibernated, suspended, or even running. So you need something, to disconnect really all shares as it automatically happens at shutdown, willingly at hand of the user. You can reply, that one can check all boxes in the dialog. But that is exactly what the -a switch does. It uses the original script-logic to determine what is to be unmounted, when you check all the boxes. And there are use-cases, when this is usefull. I put my additions under the Headline more flexible, which means, you can call a silently acting script automatically from different locations of the OS when needed (see above the pre-down example), you could as well call it from the suspend-to-ram script or from hibernate-script. As well you could tell disconnectshares to do the job silently and without bothering you. Exactly this does my -a option. And if you even don’t want to be informed by the script, that it has done its job, you can use -sa option; you can see your mount vanish in SpaceFM devices-sidebar, which is sufficient information. No poster-size messagebox fills your screen if you don’t want it nor need it.
It is disputable that “it is obvious that all shares have to be unmounted” simply because you use wlan.
You are right here. I only think it’s obvious. My reasons I explained above, but may be I’m “on the woodway” with all that, as we call it in Germany (meaning: I’d be on the up and up), and you shouldn’t hesitate to object to my statements.
For sure there are cases, we are not able to cover: Network-cable plugged of without stopping the processes which use it right in that moment, as well as user switching off the hardware-wlan-switch before disconnecting (and finishing writing on his shares) beforehand. But this is in the responsibility of the user.
As I understand your script disconnects all SMB shares of of the entire server in one shot?
Not of the entire server, but all the shares you have mounted on your client (i.e. your notebook) at that time, which saves you from checking all the boxes before network-connection is shut down, or you suspend or hibernate your notebook, having a clean state when resuming at a different location. If you neglect to do the first disconnect, i noticed some confusion later, when trying to reconnect to your samba-server, once back at the first location again. Since the the network-management tools (which is WiCD in 17.4.1 per default as far as I understand) support post-up and pre-down scripts, you can put a link to disconnectshares there to be called at the right time.
It is obvious that you can’t use any of the new options, when you really want to check only some of the boxes in the dialog-box.
Now finally, what is the -file swich good for?
I think this is the most important part of the additions. In my eyes the correct way to handle the shares is: unmount them, before the connection is interrupted, mindless of what is the reason. Hence not only shutdown needs a disconnect, but also suspend-to-ram, hibernate, and – if user choses it – even pre-down of networking, all of witch don’t need come to the attention of the user, since it is obvious that the shares have to be mounted again after resume in these cases automatically.So let me conclude:
– the antix suspend-to-ram helper script (named desktop-session-exit -S ) should call precautionary the disconnectshares-script silently (-s), and make sure to call connectshares with the previously unmounted shares silently as well. If there is nothing to unmount the script will do nothing in this case, not even show a messagebox. The original disconnectshare-script allready writes a temp file (/tmp/disconnectshares.rpt) which contains what it has done. From this file (or a similar, which could become easyly created by the script) connectshares could tell exactly, what to mount in this mode (which would be have been to be added in connectshares-script for this purpose)
So this is in my view a first step to make some thinks work smoother only. In my tests with the RIM 2000-Notebook (see wellcome-section of the forum) I noticed, that often it doesn’t recover correctly from suspend-to-ram, when a samba-share was still connected. And shares refused sometimes (not every time) working after resume. (This was true at least with noveau-driver, which I had to dismiss unfortunately after kernel-upgrade and replace it by nvidia-legacy).Sorry for the long text! I’m not able to write as concise in English language as I’m used to in German, so I need much more words to express what I want to say substantially.
- This reply was modified 2 years, 6 months ago by Robin. Reason: sentence structure was out of order
- This reply was modified 2 years, 6 months ago by Robin. Reason: Klammersetzung was wrong
- This reply was modified 2 years, 6 months ago by Robin.
Windows is like a submarine. Open a window and serious problems will start.
-
AuthorPosts
- You must be logged in to reply to this topic.