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.


2 Answers 2


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:


#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

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!

  • Thank you GabrielF. I now have to understand the commands after dbus-monitor...
    – useful
    Jan 6, 2014 at 13:13
  • The link doesn't use dbus-monitor. You found a different solution?
    – GabrielF
    Jan 6, 2014 at 16:21
  • @GabrielF HAAAA thanks mate works like magic, this is exactly what I was looking for :D
    – zulucoda
    Oct 16, 2016 at 9:55
  • /var/logs/auth.log does not exist on my Ubuntu 17.10 for some reason. I dislike this answer because it requires installing a special package, Swatch, and understanding low-level things when Gnome should provide a way to run a user-supplied command upon unlock, separate from the startup scripts. At least unix.stackexchange.com/a/28183/21372 uses dbus-monitor which seems to be installed already, but still requires some low level knowledge to run that in the background from a startup script.
    – bgoodr
    Mar 3, 2018 at 19:15
  • I am using ubuntu 16.04 the file auth.log does not exists at /var/logs/auth.log but at /var/log/auth.log.
    – CoralK
    Aug 31, 2019 at 21:10

.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

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

  • 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, 2014 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, 2014 at 13:10
  • 6
    .bashrc isn't sourced when you lockout or login a graphical session.
    – Braiam
    Jan 8, 2014 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, 2014 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, 2014 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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