Page 1 of 2 12 LastLast
Results 1 to 10 of 31

Thread: How can I specify a logout script?

Hybrid View

  1. #1
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,261
    Distro
    Ubuntu

    Question How can I specify a logout script?

    In Natty 11.04, I could specify actions to take when logging out by adding commands to /etc/gdm/PostSession/Default.

    But now, in 12.04 (fresh installation, fully updated), the folder /etc/gsm no longer exists.

    How do I specify a logout script?
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

  2. #2
    Join Date
    Feb 2009
    Location
    Dallas, TX
    Beans
    7,790
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: How can I specify a logout script?

    Hi Paddy Landau.

    Precise is not using gdm anymore. Instead, lightdm is the defualt display manager.

    You still will be able to set your login, and logout script, but in a slightly different way. The config file now is:
    Code:
    /etc/lightdm/lightdm.conf
    And the relevant fields are:
    Code:
    session-setup-script
    session-cleanup-script
    I hope that helps, and tell us how it goes.
    Regards.

  3. #3
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,261
    Distro
    Ubuntu

    Re: How can I specify a logout script?

    Thank you, papibe.

    That does indeed work.

    There is a twist, though: the script runs as root and yet ${USER} and ${HOME} are set for the user who is logging in or out.

    Therefore, to run a command as the required user, you have to use:
    Code:
    su "${USER}" --command "command-to-run"
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

  4. #4
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,261
    Distro
    Ubuntu

    Re: How can I specify a logout script?

    I am reopening this thread, because the previously-described solution no longer works.

    I have tried everything that I can think of (which is not much), but the specified logout script just no longer runs.

    So, the question again is:

    How do I specify a logout script?
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

  5. #5
    Join Date
    Feb 2011
    Location
    Somewhere...
    Beans
    1,554
    Distro
    Ubuntu 14.10 Utopic Unicorn

    Re: How can I specify a logout script?

    There's a quick and probably dirty solution: Add the command to .bash_logout . It's like .profile, but it executes when a user logs out.

  6. #6
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,261
    Distro
    Ubuntu

    Re: How can I specify a logout script?

    Quote Originally Posted by zombifier25 View Post
    There's a quick and probably dirty solution: Add the command to .bash_logout . It's like .profile, but it executes when a user logs out.
    Thanks, but that does not work for Ubuntu.

    .bash_logout is executed when logging out from a console (e.g. Ctrl+Alt+F1), but not from a GUI session.
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

  7. #7
    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#

  8. #8
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,261
    Distro
    Ubuntu

    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.
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

  9. #9
    Join Date
    May 2008
    Location
    United Kingdom
    Beans
    5,261
    Distro
    Ubuntu

    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}.
    Always make regular backups of your data (and test them).
    Visit Full Circle Magazine for beginners and seasoned Linux enthusiasts.

  10. #10
    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

Page 1 of 2 12 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
  •