LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-05-2017, 10:06 AM   #1
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,718
Blog Entries: 3

Rep: Reputation: 107Reputation: 107
which 'log out' is the last one?


I want to run a script when I perform a logout from my desktop session. Typically, my session looks like this:
  • login
  • launch a group of GUI apps into the desktop
  • open shells into the desktop
  • work (grin)
  • logout
I have per-user things that run when I start this session. Some of them require "shutdown actions" so I need to do those actions when the session ends.

I could use $HOME/.bash_shutdown that executes when a login-shell exits. However, there may be multiple login-shells during the course of the session and I don't want to run the shutdown actions for each login-shell but at the end of the session.

Two other related questions:
Q1 Is there some way for a shell script to learn if it is running in a login-shell vs. other environments?
Q2 Does the desktop session have controlling scripts similar to what is available through $HOME/.bashrc and $HOME/.bash_logout?

Thanks in advance,
~~~ 0;-Dan
 
Old 05-05-2017, 02:49 PM   #2
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,745

Rep: Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791
Here is something like this for $HOME/.bash_logout
Code:
# Count my login terminals
# This hack works in most Unixes:
logins=`\who -u | \awk '$1==u&&$NF!~/^\(?:[0-9]+\..\)?$/{++s}END{print s+0}' u="$USER"`
[ $logins -gt 1 ] && exit

# This will exit in sudo or su - or if utmp is broken:
mylogin=`\who -m | \awk '$1==u' u="$USER"`
[ -z "$mylogin" ] && exit
 
Old 05-11-2017, 02:03 PM   #3
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,718

Original Poster
Blog Entries: 3

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by MadeInGermany View Post
Here is something like this for $HOME/.bash_logout
Code:
# Count my login terminals
# This hack works in most Unixes:
logins=`\who -u | \awk '$1==u&&$NF!~/^\(?:[0-9]+\..\)?$/{++s}END{print s+0}' u="$USER"`
[ $logins -gt 1 ] && exit

# This will exit in sudo or su - or if utmp is broken:
mylogin=`\who -m | \awk '$1==u' u="$USER"`
[ -z "$mylogin" ] && exit
Is there something that I can query within a script to learn if it is running as a "login" shell?

Follow-up: The bash shell has 'options'. One of these options is (ta-da) login_shell. You can query this option using:
Code:
prompt$  shopt  |  grep login_shell
login_shell    	xxxx
The string, 'xxxx' will have the value "on" or "off" -- "on" if this script is running in a login shell.
NOTE -- a Cinnamon DE terminal window is not a login shell and reports "off".


It seems that I could have $HOME/.bashrc bump a counter for each LOGIN and the check that counter during $HOME/.bash_logout.

I suspect that I'm really looking for is not "login" but desktop "session" termination.

Last edited by SaintDanBert; 05-15-2017 at 04:53 PM.
 
Old 05-11-2017, 02:10 PM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 17,263
Blog Entries: 10

Rep: Reputation: 5160Reputation: 5160Reputation: 5160Reputation: 5160Reputation: 5160Reputation: 5160Reputation: 5160Reputation: 5160Reputation: 5160Reputation: 5160Reputation: 5160
Quote:
Originally Posted by SaintDanBert View Post
I suspect that I'm really looking for is not "login" but desktop "session" termination.
Code:
killall xinit
???
 
Old 05-12-2017, 02:55 AM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,745

Rep: Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791
You mean how to trigger a logout script when a desktop exits?
I remember the CDE desktop runs $HOME/.dt/sessions/sessionexit if present.
But I did not find anything similar in Gnome or KDE.
 
Old 05-15-2017, 04:48 PM   #6
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,718

Original Poster
Blog Entries: 3

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by MadeInGermany View Post
You mean how to trigger a logout script when a desktop exits?
I remember the CDE desktop runs $HOME/.dt/sessions/sessionexit if present.
But I did not find anything similar in Gnome or KDE.

When you say CDE do you mean the Cinnamon Desktop Environment?

Thanks in advance,
~~~ 0;-Dan
 
Old 05-16-2017, 01:06 PM   #7
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 17,263
Blog Entries: 10

Rep: Reputation: 5160Reputation: 5160Reputation: 5160Reputation: 5160Reputation: 5160Reputation: 5160Reputation: 5160Reputation: 5160Reputation: 5160Reputation: 5160Reputation: 5160
^ no.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to fix "Please have a look at the log file for details: /var/log/jockey.log" harisuciha Linux - Hardware 3 04-29-2012 12:59 PM
kernel log format in /var/log/kern.log sinu_nayak2001 Linux - Newbie 2 10-07-2009 08:34 AM
In Apache server, How to change log file location and log format for access log fil? since1993 Linux - Server 1 08-19-2009 04:14 PM
Can Samhain log my entries in /var/log/secure and /var/log/mesage to a central server abefroman Linux - Software 2 04-13-2008 04:13 PM
Opennms Logs - where are web.log, web_rtc.log and webauth.log referenced? not_much_of_a_guru Linux - Networking 0 07-12-2006 10:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration