Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

In Saucy salamander I need to run a script each time I login then each time I unlock the session after manual lock or auto sleep. I can't use "Startup Application" for that because it wouldn't trigger on unlock.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Found this, which was made by Ubuntu Forums user opus1. Maybe it can help.


This is what the post gives as a solution:

For anyone interested, here's what I did: I looked at the logs (specifically /var/logs/auth.log) and saw that an entry is made when ever the password is checked and accepted. My log said:

Aug  7 14:10:57 mumble gnome-screensaver-dialog: gkr-pam: unlocked login keyring

Ultimately I found an application called "Swatch" which monitors a log for you and will run a script when a string that you specify appears in that log. Swatch requires a config file (.swatchrc), and mine looks like this:

watchfor /unlocked login keyring/
  exec /root/.gnome2/nautilus-scripts/wakeServer

where "/unlocked login keyring/" is the string to look for and "exec" defines the script to run when it is found. My wakeServer script looks like this:

#!/bin/bash

#wake the server
wakeonlan AA:BB:CC:DD:EE:FF

#record info in the log file
myVar="woke server at login:"
echo "$myVar">>/home/me/.serverWake.log
date>>/home/me/.serverWake.log

where "AA:BB:CC:DD:EE:FF" is the MAC address of my server.

Swatch will need to be entered as a start-up application (create an entry in System | Preferences | Startup applications called "runSwatch" and make the command "swatch --tail-file /var/log/auth.log --daemon". (In Debian, only root can read logs So the start up command needs to be prefaced with "sudo" and swatch will need to be added to the sudoers file without a password. In Ubuntu it appears non-root users can read logs. There could be a security issue with granting password-less access to swatch, but in my case it seems acceptable).

So far it has worked perfectly!

share|improve this answer
    
Thank you GabrielF. I now have to understand the commands after dbus-monitor... –  useful Jan 6 at 13:13
    
The link doesn't use dbus-monitor. You found a different solution? –  GabrielF Jan 6 at 16:21
2  
@GabrielF While this technically answers the question, it would be preferable if you provide the key points in the link as part of your answer, in the off-chance the link ends up dying eventually. –  Thomas W. Jan 8 at 17:46
    
@ThomasW. I understand your concern, and I believe that's quite an interesting issue, but don't I need permission (either from the author or the website) to copy the relevant parts? –  GabrielF Jan 8 at 18:13
2  
@GabrielF I discussed this with one of our moderators (RolandiXor), and this here link is the bookmarked chat on this issue. They agree that that philosophy does not apply in this instance, and that you SHOULD include the key points of the link that you have linked to in this answer. That philosophy you linked to is a good idea, but ultimately you SHOULD include the key points from a link in an answer, rather than just a link-only answer, because link-only answers aren't great. –  Thomas W. Jan 8 at 19:50

.bashrc will be the place you want to use for that process. .bashrc holds users' profile and all of configurations, and that's what system will read first thing when you log in, therefore that's where you want to put your codes for your customized scripts to run upon logging in.

Here's an example from my codes that I use. This is code I added to the bottom line of .bashrc:

if [ -f ~/.myscripts ]; then
. ~/.myscripts
fi

And .myscripts holds my scripts in bash shell that I want to be fired off when I log in.

share|improve this answer
    
Sorry it doesn't work although ~$ ls -aF .my* .myscripts* and I added the reference to .bashrc. I tried tweaking .bashrc with force prompt color just to see how this work and I don't even need to unlog to see the change, just close re-open the terminal. when i run . /.myscripts from terminal the script works ok but is not triggered when I log in a locked tty7. –  useful Jan 5 at 11:42
    
I believe I begin to understand. This will maybe work in addition with the link below given by GabrielF. Thank you Faron. –  useful Jan 6 at 13:10
2  
.bashrc isn't sourced when you lockout or login a graphical session. –  Braiam Jan 8 at 19:53
    
Yes, but I ended in understanding it is a place from which one can launch a resident script (the one that will monitor logon). An other guy proposed a different solution: /etc/pm/sleep.d/20_kill-notify-osd bugs.launchpad.net/ubuntu/+source/gnome-settings-daemon/+bug/… –  useful Jan 10 at 15:41
    
upvote for @Braiam in pointing out when it's not sourced upon lock out or logging via graphical. No wonder why few of my scripts didn't function properly. –  Faron Jan 11 at 13:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.