Results 1 to 9 of 9

Thread: Cached script content?

  1. #1
    Join Date
    Apr 2011
    Location
    Stockholm
    Posts
    81

    Default Cached script content?

    I mount a network share using cifs which for many years has been done using this command:
    Code:
    sudo mount -t cifs //path-to-network-share  -o username=gostal,uid=myUID,gid=myGID
    (myUID and myGID are 4-digit numbers) and the share is successfully mounted when password is entered on the command line.

    Recently my system admins have done two things:
    1 Provided a GIU-activated shell script where the password is entered in the GUI
    2 Required a 16-character password containing at least one special character (!"#¤%& ...)

    1 works by storing the password in a variable which is then referenced in the actual mount command.
    2 GUI-activated shell script doesn't work with the new password.

    My new password contains a " which most likely is the reason why the GUI-activated shell script is not happy any more but this is only because the password is stored in a variable. Manually mounting on the command line still works. This means that the shell makes a different interpretation of what is stored in the password variable compared to what is entered on the command line. I can live with that. But here is the irritating thing:

    I copied the shell script tied to the GUI like so:
    Code:
    sudo cp /usr/local/bin/mountsmb.sh /usr/local/bin/mountsmb.sh.bak
    sudo cp /usr/local/bin/mountsmb.sh /usr/local/bin/mountsmb.sh.mod
    I made modifications to the .mod-file and then copied back to mountsmb.sh

    The password line is this:
    Code:
    CPASS=$(zenity ${HEADLINE} --password --text "SMB-montering av $2, ange lösenord för Windows") ; CHECKCANCEL
    and storing the password in this way does not work so then I put quotation marks around the definition:
    Code:
    CPASS="$(zenity ${HEADLINE} --password --text "SMB-montering av $2, ange lösenord för Windows")" ; CHECKCANCEL
    When I tried the GUI after having modified the script it still didn't work so I thought this modification didn't do the trick but then I tried running the .mod-file instead and that worked!! Did I forget to copy? No, same mdsum on both mountsmb.sh and mountsmb.sh.mod

    This was last Friday the 25th of May. So I think that the shell script once run is cached somewhere so my modification was ignored. Still today there is a difference between the cached file (if caching is what's going on) and the file on the disk. Sitting in /usr/local/bin today I did:
    Code:
    sudo cat mountsmb.sh
    and that gives me the old file but doing instead
    Code:
    sudo cat /usr/local/bin/mountsmb.sh
    gives me the modified one. Apparently the file references point to different objects though they really should be the same!

    If there is a cache somewhere, how do I flush it? And where is the documentation? This behavior does not really help when trying to isolate problems because the system response is to some other input than what I think I'm giving.

  2. #2
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,143

    Default Re: Cached script content?

    Quote Originally Posted by gostal View Post

    This was last Friday the 25th of May. So I think that the shell script once run is cached somewhere so my modification was ignored. Still today there is a difference between the cached file (if caching is what's going on) and the file on the disk. Sitting in /usr/local/bin today I did:
    Code:
    sudo cat mountsmb.sh
    and that gives me the old file but doing instead
    Code:
    sudo cat /usr/local/bin/mountsmb.sh
    gives me the modified one. Apparently the file references point to different objects though they really should be the same!

    If there is a cache somewhere, how do I flush it? And where is the documentation? This behavior does not really help when trying to isolate problems because the system response is to some other input than what I think I'm giving.
    Apart from what you typed before this QUOTE, I like to comment on this.

    You apparently think that you proved the things you tell by showing those commands.
    But we only belive your computer evidence when you post it including the prompt, the command, the output and the next prompt. Now we have only the command and nothing else. Also, has this file no world read permission? This because you do the cat as root, where one should not use root when not strictly needed to do so.

    IMHO a better test (and evidence) would be
    Code:
    cd /usr/bin/local
    ls -l mountsmb.sh
    cat mountsmb.sh
    cat /usr/bin/local/mountsmb.sh
    or, when a normal user is not able to read there:
    Code:
    su -
    cd /usr/bin/local
    ls -l mountsmb.sh
    cat mountsmb.sh
    cat /usr/bin/local/mountsmb.sh
    exit
    And no, I do not know of any cache when you edit a text file. And yes, I assume you are looking at two different places.
    Henk van Velden

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,143

    Default Re: Cached script content?

    Quote Originally Posted by gostal View Post
    The password line is this:
    Code:
    CPASS=$(zenity ${HEADLINE} --password --text "SMB-montering av $2, ange lösenord för Windows") ; CHECKCANCEL
    and storing the password in this way does not work so then I put quotation marks around the definition:
    Code:
    CPASS="$(zenity ${HEADLINE} --password --text "SMB-montering av $2, ange lösenord för Windows")" ; CHECKCANCEL
    The "..." quoting your are trying to improve here is a construct where the " are used in pairs. By adding them at the begin and the end, you now have a strange quoting in the command. One that you probably do not want.
    Code:
    CPASS="$(zenity ${HEADLINE} --password --text "SMB-montering av $2, ange lösenord för Windows")" ; CHECKCANCEL
    The two red parts are now the parts quoted. What is in between has now spaces that lead to word splitting by the shell. OTOH there is also The $(...) construct around it. The result might be difficult to predict .
    Henk van Velden

  4. #4
    Join Date
    Apr 2011
    Location
    Stockholm
    Posts
    81

    Default Re: Cached script content?

    Thanks for the feedback. I'll try your suggestions and get back with a hopefully solid (read full computer prompt, input and output) report but it'll have to wait as I'll be out of office a few days.
    I had a quick go and the problem seems to be connected to the use of sudo but more on this later. Thanks again.

  5. #5
    Join Date
    Apr 2011
    Location
    Stockholm
    Posts
    81

    Default Re: Cached script content?

    Please forgive me for posting a somewhat silly question. The cache idea was all my bad caused by me looking at different lines in the file and to some extent also unexpected behavior. So there is still some before-after issue. Starting the mounting script /usr/local/bin/mountsmb.sh with the desktop icon used to work and all I had to do was to type in the password in the window the script fired up. The construct with the extra quotation marks (in red):
    Code:
    CPASS="$(zenity ${HEADLINE} --password --text "SMB-montering av $2, ange lösenord för Windows")" ; CHECKCANCEL
    does work but not in the same way. Now the process requires me to give the password twice and there is only one opportunity to do so when using the desktop icon. However, starting the script by hand on the command line:
    Code:
    /usr/local/bin/mountsmb.sh //filer1-kst/gostal M-disk
    actually prompts for the password again (first it was given in the window that the script fires up):
    Code:
    gostal@k2003734:~> /usr/local/bin/mountsmb.sh //filer1-kst/gostal M-disk
    Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.
    Password for gostal@//filer1-kst/gostal:  *************** #This is the second password.
    //filer1-kst/gostal   15G   14G  2.0G  87% /home/gostal/mnt/M-disk
    Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.
    Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.
    gostal@k2003734:~>
    The reason why I got it to work when I did:
    Code:
    gostal@k2003734:~> sudo /usr/local/bin/mountsmb.sh.mod //filer1-kst/gostal M-disk
    is that the extra password was already given. Didn't have anything to do with the fact that I used a different file.

    So now the question is: why is the extra password needed now? As far as I know there have been only two changes: 1 the new password and 2 the extra quotation marks in the script. Below is the script in full (with the extra quotation marks in red):
    Code:
    gostal@k2003734:/usr/local/bin> cat mountsmb.sh
    #!/bin/sh
    # Script: mountsmb.sh <smb-area> <mountpoint>
    #         mountsmb.sh //filer1-kst/$USER M-disk
    # Montering av en smb-katalog via ikon på Desktop
    # monterar kataloger i ~/mnt/...
    # Sml   Rev 2.1 2013-05-15
    #       2013-11-29 Monteringrättigheter 700
    #       2015-04-01 Fix av df-test
    # 2015-11-06 Sml Vers. med zenity (gnome)
    ####################################################
    #
    HEADLINE=" --title mountsmb"
    CHECKCANCEL  ()  { if [ $? = "1" ] ; then exit ; fi }
    CHECKCANCEL2 ()  { STATUS=$? ; if [ $? = "2" ]; then exit ; fi }
    CHECKERROR   ()  { if test -s ${ERR};then echo -e "---\n$1\n" >> ${ERR} ; zenity ${HEADLINE} --info --text "$(cat ${ERR})" ;rm ${ERR} ; exit ;fi }
    
    DESKTOPICON ()  { 
    echo "[Desktop Entry]
    Comment[en_US]=
    Comment=
    Encoding=UTF-8
    Exec=/usr/local/bin/mountsmb.sh "$1" "$2"
    GenericName[en_US]=Open Windows SMB-disk
    GenericName=Open Windows SMB-disk
    Name[en_US]="$2"
    Name="$2"
    Path=
    StartupNotify=true
    Terminal=false
    TerminalOptions=-geometry 600x100+50+50
    Type=Application
    X-DBUS-ServiceName=
    X-DBUS-StartupType=
    X-DCOP-ServiceType=
    X-KDE-SubstituteUID=false
    X-KDE-Username="
    }
    
    if [ "$1" = "" ]; then echo -e "\n## Parametrar saknas:\n   ex.: mountsmb.sh //filer1-kst/$USER M-disk\n";exit;fi
    if [ "$2" = "" ]; then echo -e "\n## Parametrar saknas, för <mountpoint>\n   ex.: mountsmb.sh //filer1-kst/$USER M-disk\n";exit;fi
     
    FILERAREA="$1"
    MOUNTAREA="$HOME/mnt/$2"
    ERR="/tmp/mount-error-$USER"
    
    if [ $USER = "root" ]; then zenity ${HEADLINE} --warning --text "No script for root, exit" ; exit ; fi
    test -d $HOME/mnt    ||  $(zenity ${HEADLINE} --info --text "Skapar katalog: $HOME/mnt";CHECKCANCEL;mkdir $HOME/mnt)
    test -d $HOME/mnt/$2 ||  $(zenity ${HEADLINE} --info --text "Skapar monteringspunkt: $HOME/mnt/$2";CHECKCANCEL;mkdir $HOME/mnt/$2)
    test -f $HOME/Desktop/$2.desktop ||  DESKTOPICON $1 $2 > $HOME/Desktop/$2.desktop
    
    INUSE=$(df -h 2> /dev/null | grep ${MOUNTAREA} )
    
    if [ "${INUSE}" = "" ]; then
         CPASS="$(zenity ${HEADLINE} --password --text "SMB-montering av $2, ange lösenord för Windows")" ; CHECKCANCEL
        sudo -S /bin/mount -t cifs ${FILERAREA} ${MOUNTAREA} -o workgroup=win,username=$USER,password=$CPASS,uid=$USER,soft,file_mode=0700,dir_mode=0700 2>> ${ERR}
        CHECKERROR "Kontrollera lösenord eller rättighet mot monteringen"
        df -h ${MOUNTAREA} | grep filer && zenity ${HEADLINE} --info --text "${FILERAREA} monterad i $HOME/mnt/$2"
    fi
    
    CHOISE=$(zenity ${HEADLINE} --list --text="Options" --radiolist --column="1" --column="2" TRUE "File-Manager" FALSE "Använd" FALSE "Avmontera" --hide-header) 
            CHECKCANCEL
    if [ "${CHOISE}" = "File-Manager" ]; then dolphin ${MOUNTAREA} 2>> /dev/null & fi
    if [ "${CHOISE}" = "Avmontera" ]; then sudo -S /bin/umount ${MOUNTAREA} 2>> ${ERR}
            if [ "$(df -h|grep $USER/mnt)" ] ; then
              zenity --question --text "Katalogen ${MOUNTAREA} är avmonterad\n\nFöljande areor är fortfarande monterade:\n\n$(df -h|grep /mnt)\n\nVill du avmontera dessa också"
              if [ "$?" = "0" ] ; then sudo -S /usr/bin/umount "$(mount|grep $HOME|awk '{print $3}')" 2>> ${ERR} ; fi
            fi
    fi
    CHECKERROR "Kontrollera om monteringen används någonstans"
    exit
    Permissions:
    Code:
    gostal@k2003734:/usr/local/bin> ls -l mountsmb.sh
    -rwxr-xr-x 1 root root 3147 Jun  1 11:36 mountsmb.sh
    This is the desktop icon file and permissions:
    Code:
    gostal@k2003734:~/Desktop> ls -l M-disk.desktop
    -rwxr--r-- 1 gostal inst69 445 May 25 09:46 M-disk.desktop
    gostal@k2003734:~/Desktop> cat M-disk.desktop
    [Desktop Entry]
    Comment[en_US]=
    Comment=
    Encoding=UTF-8
    Exec=/usr/local/bin/mountsmb.sh //filer1-kst/gostal M-disk
    GenericName[en_US]=Open Windows SMB-disk
    GenericName=Open Windows SMB-disk
    Icon=user-home
    MimeType=
    Name[en_US]=M-disk
    Name=M-disk
    Path=
    StartupNotify=true
    Terminal=false
    TerminalOptions=-geometry 600x100+50+50
    Type=Application
    X-DBUS-ServiceName=
    X-DBUS-StartupType=
    X-DCOP-ServiceType=
    X-KDE-SubstituteUID=false
    X-KDE-Username=

  6. #6
    Join Date
    Apr 2011
    Location
    Stockholm
    Posts
    81

    Default Re: Cached script content?

    There is one more issue that I just noted:

    Although the share, M-disk, gets mounted using:
    Code:
    gostal@k2003734:~> /usr/local/bin/mountsmb.sh //filer1-kst/gostal M-disk
    it doesn-t get the right permissions:
    Code:
    gostal@k2003734:~/mnt> ls -l
    total 16
    -rw-r--r-- 1 gostal inst69    0 Jun  1 14:26 dirlist.txt
    drwxr-xr-x 2 gostal inst69 4096 Oct 27  2017 it000198_c_drive
    drwxr-xr-x 2 gostal inst69 4096 Nov 30  2017 ki003401_c_drive
    drwxr-xr-x 2 gostal inst69 4096 Nov 11  2017 m1
    drwxr-xr-x 2 root   root      0 Apr 10  2017 M-disk
    drwxr-xr-x 2 gostal inst69 4096 Oct 10  2017 sccmsources
    I want:
    Code:
    gostal@k2003734:~/mnt> ls -l
    total 20
    -rw-r--r-- 1 gostal inst69  347 Jun  1 14:26 dirlist.txt
    drwxr-xr-x 2 gostal inst69 4096 Oct 27  2017 it000198_c_drive
    drwxr-xr-x 2 gostal inst69 4096 Nov 30  2017 ki003401_c_drive
    drwxr-xr-x 2 gostal inst69 4096 Nov 11  2017 m1
    drwxr-xr-x 2 gostal inst69    0 Apr 10  2017 M-disk
    drwxr-xr-x 2 gostal inst69 4096 Oct 10  2017 sccmsources
    which I get if I do:
    Code:
    gostal@k2003734:~> sudo mount -t cifs //filer1-kst/gostal /home/gostal/mnt/M-disk/ -o username=gostal,uid=myUID,gid=myGID

  7. #7
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,143

    Default Re: Cached script content?

    Well, doing the mount yourself you will get what you have there:
    Code:
    uid=myUID,gid=myGID
    (where I hope you have the correct numbers there. Again, all you keep secret or all you change from what it is really will only increase misunderstandings and confusion).

    Because I can not see what the other mount statement is, I can not comment on it's results at all.

    But when you mount this file system rather often, I wonder why you do not have an entry for it in /etc/fstab. Then all the parameters are there and you are freed of typing them (including to being careful of mistypings). It will shorten your mount statement to
    Code:
    mount /home/gostal/mnt/M-disk/
    All the rest will then be found by the mount program in /etc/fstab.
    You might want to add
    Code:
    noauto
    to that entry though, else the system will try to mount it on boot.

    And when
    Code:
    mount /home/gostal/mnt/M-disk/
    is still too long, make it a very short script in /home/gostal/bin. E.g. a file named mm (or what you like)
    Code:
    #!/bin/bash
    mount /home/gostal/mnt/M-disk/
    Alternative create an alias.
    Last edited by hcvv; 01-Jun-2018 at 05:55.
    Henk van Velden

  8. #8
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,282
    Blog Entries
    2

    Default Re: Cached script content?

    Just a personal question,
    Is there a reason you didn't "echo" your variable after you wrote to it to verify it's what you expected?

    And,
    I'd expect using zenity should be unnecessary if you're familiar with using a command line console... That's unnecessary complication that can only increase the chances of something going wrong. Seems to me that you should be able to simply use the mount command you've always done before, whether manually or auto mounting in an fstab.

    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  9. #9
    Join Date
    Apr 2011
    Location
    Stockholm
    Posts
    81

    Default Re: Cached script content?

    Quote Originally Posted by tsu2 View Post
    Just a personal question,
    Is there a reason you didn't "echo" your variable after you wrote to it to verify it's what you expected?
    And,
    I'd expect using zenity should be unnecessary if you're familiar with using a command line console...
    ...

    TSU
    I did "echo" during my various attempts at fixing the zenity mount script but in the end I just copied what seemed to work to the original script but at that point I had not noticed that I got wrong permissions. Also, a correct echo doesn't necessarily mean that the script works as intended.

    But as you hint the whole thing is rather academic since I do have a working method and it's really my sysadmin's headache to fix the script. But I had to dip my nose in it, didn't I?

    Anyway, by now I think that pretty much all meaningful things have been said so thanks again, guys, for the input. Over and out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •