Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 31

Thread: How can I specify a logout script?

  1. #21
    Join Date
    Jun 2013
    Beans
    5

    Re: How can I specify a logout script?

    My workaround (also using encrypted $HOME)
    (as root)
    mv /bin/umount /bin/umount.d
    vi /bin/umount
    put in this:
    #!/bin/bash
    PASS=$*
    if [[ ! `/usr/bin/w | grep gnome-session` ]]; then
    # need to check for active sessions as su and exiting from shells can call umount
    /bin/logout-lightdm # containing suggested scipt pointing to /home/usr/bin/.bash_logout
    fi
    /bin/umount.d $PASS
    exit 0

    then
    chmod 4755 /bin/umount

    Not nice but logout and reboot worked. Or has the issue been fixed?

  2. #22
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    4,270
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How can I specify a logout script?

    Quote Originally Posted by dwok View Post
    My workaround….
    Thanks for posting your solution.

    Quote Originally Posted by dwok View Post
    … has the issue been fixed?
    The issue that I still have (as explained at the end of post #20) still remains. Otherwise, it works. Does your solution work when logging out and in again?

    By the way, your last line:
    Code:
    /bin/umount.d $PASS
    You need to quote the password in case it contains certain special characters, thus:
    Code:
    /bin/umount.d "${PASS}"
    Last edited by Paddy Landau; June 21st, 2013 at 04:21 PM.
    Problems with WINE?
    Full Circle Magazine :: Confused "allot"? :: Cheap Linux stickers
    In my day, we had outdoors in which to run, play, and socialise. Now we have computers to do those.

  3. #23
    Join Date
    Jun 2013
    Beans
    5

    Re: How can I specify a logout script?

    PASS are just the parameters that are passed on when using umount
    eg: umount /media/disk
    so I was not expecting any special characters but thanks and I will change it just in case.
    My work around is a wrapper that is called when the system is using umount.
    As in this case when you log out your .privat will be un-mounted.
    So the answer is yes it works using logout and reboot because I'm telling the system
    to do my stuff and then pass on the umount command.
    Tested on 12.04

    Hope this clarifies.

  4. #24
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    4,270
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How can I specify a logout script?

    Thanks for the reply, dwok.

    In testing your method, I see that neither ${USER} nor ${HOME} is set for the user who is logging out. Therefore, your method will work only for a single-user machine where you know the user beforehand.

    Also, where I suggested that you use "${PASS}", this is not quite correct, as there may be multiple parameters. If none of the parameters contains spaces, you can use ${PASS}; but if any parameter contains a space (which is possible, albeit rare), it will fail.

    Instead, you will need to use "${@}", without using PASS at all:
    Code:
    /bin/umount.d "${@}"
    Problems with WINE?
    Full Circle Magazine :: Confused "allot"? :: Cheap Linux stickers
    In my day, we had outdoors in which to run, play, and socialise. Now we have computers to do those.

  5. #25
    Join Date
    Jun 2013
    Beans
    5

    Re: How can I specify a logout script?

    Correct I only had one user.
    I have now set up a few more (without encrypted $HOME but umount is called anyway) I have modified my /bin/umount to execute a script in /TEST
    You are right with that /bin/umount does not have $USER or $HOME set, but funny enough when it then calls the test script they are set again:
    ### logout dwok1
    start Umount: <- echo from /bin/umount
    Umount id:
    uid=0(root) gid=1001(dwok1) groups=0(root),1001(dwok1) <- interesting to see that the last row from "id" shows the user
    root
    UMOUNT calling new_test.sh
    START new_test.sh <- begin of script called by /bin/umount
    clean USER: dwok1 <- $USER is set
    clean HOME: /home/dwok1 <- $HOME is set
    Next lines from id
    uid=0(root) gid=1001(dwok1) groups=0(root),1001(dwok1) <- again root user is executing but last entry is our actual user
    END new_test.sh <- script ended
    UMOUNT now unmounting <- back to umount to execute the umount command.
    ### logout dwok3
    start Umount:
    Umount id:
    uid=0(root) gid=1003(dwok3) groups=0(root),1003(dwok3)
    root
    UMOUNT calling new_test.sh
    START new_test.sh
    clean USER: dwok3
    clean HOME: /home/dwok3
    Next lines from id
    uid=0(root) gid=1003(dwok3) groups=0(root),1003(dwok3)
    END new_test.sh

    So this should work for your multiple users logging out.
    you need to check if the "gnome-session" (use "w" and grep for user don't use "ps") is still running for that user - only if not then
    execute your stuff, otherwise it will always execute.

    During shutdown umount is called 6 times - during the first time $USER and $HOME is set
    after that is it no longer set.

    I think this info should be enough to create a script - it is getting late for me now so I will try one another day.

    Please let me know how your testing went.

  6. #26
    Join Date
    Jun 2013
    Beans
    5

    Re: How can I specify a logout script?

    btw ${PASS} works with spaces nicely:
    more TEST.sh
    #!/bin/bash
    PASS=$*

    echo "P: #${PASS}#"

    root@my-ubox:/TEST# ./TEST.sh with -d and lots -w of spaces
    P: #with -d and lots -w of spaces#

  7. #27
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    4,270
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How can I specify a logout script?

    Quote Originally Posted by dwok View Post
    … You are right with that /bin/umount does not have $USER or $HOME set, but funny enough when it then calls the test script they are set again…
    That's all interesting. It is worth trying.

    Quote Originally Posted by dwok View Post
    btw ${PASS} works with spaces nicely..
    There's something there that I'm not understanding. I'll have to test it thoroughly to understand. If you look at the difference between $*, "$*", $@ and "$@", you will understand my confusion as to how your version manages to work.
    Problems with WINE?
    Full Circle Magazine :: Confused "allot"? :: Cheap Linux stickers
    In my day, we had outdoors in which to run, play, and socialise. Now we have computers to do those.

  8. #28
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    4,270
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How can I specify a logout script?

    Quote Originally Posted by dwok View Post
    btw ${PASS} works with spaces nicely…
    I'm not getting the same results as you. Here's my test:

    Save the following script: testQuotes.bz2
    Because of the forum restrictions, it is compressed. Decompress it and ensure that the executable bit is set with: chmod +x testQuotes

    The script tests every variation of ${*}, "${*}", ${@}, and "${@}", both from a variable and directly, and calling the receiving script (in this case a function) both with quotes and without (see the script for details).

    Now, call the script with the following line (note the multiple spaces within the third parameter):
    Code:
    ./testQuotes a 'b c' '   d   e   f   '
    The receiving script displays what it receives in each test case. What we want is for it to receive three parameters, viz. 'a', 'b c', and ' d e f ' (the latter with multiple spaces included).

    However, when you run the script, only the last one works correctly — exactly as predicted by the documentation.

    That is why I am confused as to how you are getting correct results from ${PASS}.
    Problems with WINE?
    Full Circle Magazine :: Confused "allot"? :: Cheap Linux stickers
    In my day, we had outdoors in which to run, play, and socialise. Now we have computers to do those.

  9. #29
    Join Date
    Jun 2013
    Beans
    5

    Re: How can I specify a logout script?

    No need to be confused - I'm not getting the correct results - I'm getting just results "for the umount' command - your syntax is the correct way.

    I hope I have attached a file with my scripts and log files, tested and working for multiple users calling $HOME/bin/exit_script.sh upon logout and reboot.
    With umount /cdrom and /media/xx etc.still working and not executing the exit_script.sh in each $HOME.

    I'm sure there are some syntax flaws within the scripts - this is purely about function.
    If you could please confirm if they are doing the job and feel free to provide me the scripts with a correct syntax.

    Attached Files Attached Files

  10. #30
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    4,270
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How can I specify a logout script?

    dwok, thanks for the scripts.

    It may be a couple of days before I can look at this.
    Problems with WINE?
    Full Circle Magazine :: Confused "allot"? :: Cheap Linux stickers
    In my day, we had outdoors in which to run, play, and socialise. Now we have computers to do those.

Page 3 of 4 FirstFirst 1234 LastLast

Bookmarks

Posting Permissions

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