0

I would like to run something like that on loggin in:
Logging lock-screen events

I then tried to use both systemd and upstart described in this answer: https://askubuntu.com/questions/228304/how-do-i-run-a-script-at-start-up#answer-228313

However my script is never launched on start up.
The script run fine if I launch it myself once logged in.

The script I placed to /etc/init.d/ looks like :

#!/bin/bash
### BEGIN INIT INFO
# Provides:          screenlogger
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: screenlogger
# Description:       screenlogger
### END INIT INFO

export SCREENLOGGER="$HOME/.bin/screenlogger.sh"

if [ -e "$SCREENLOGGER" ]
then
  $SCREENLOGGER
fi

Then I realised that if I just put a echo "$HOME" >> /home/myloggin/test the file will allways be empty on reboot.

Also, it seems that the script is runned at boot and not on log in and the user is root not myself.

So I would like to know if that is possible to run a script on log in as the user process owner (with $HOME fullfilled) ?

5
  • $HOME is a variable set for each single user... it is not global. What do you really want: to run as if the user x is logged or only to run from that user home? It's different... Ps> welcome (out) on SuperUser
    – Hastur
    Commented Sep 29, 2016 at 10:15
  • Have you tried using su and becoming the user you want to be executing that script?
    – sysfiend
    Commented Sep 29, 2016 at 10:21
  • ... another specification request: do you want to execute the script at boot time (when computer starts) or at log-in time (when a specific user logs)?
    – Hastur
    Commented Sep 29, 2016 at 10:22
  • if its desired to run at 'login' time put it in that users' .autostart folder on a *nix machine ~/.autostart/ OR ~/scripts and have something in the $(shell)rc calling that ~/scripts/foo.sh Commented Sep 29, 2016 at 11:06
  • (Sorry for the newlines...). I tried with the ~/.config/autostart and it does not launch at log in either. Tried mannualy to do: $ IFS== read var query <<< `cat .config/autostart/screenlogger.desktop | grep Exec` $query And works fine. Didn't find anything about ~/.autostart/.
    – Hellfar
    Commented Sep 29, 2016 at 14:44

1 Answer 1

0

I'm using ~/.xprofile for to apply user-level settings and start user-level services, for example:

xss-lock slock &

I've never had problems with X not being initialised at the point when this file is run.

2
  • Running the script before that X11 is initialised wont let me monitor org.mate.ScreenSaver or maybe I missed something.
    – Hellfar
    Commented Sep 29, 2016 at 14:38
  • I finally used your solution sleep 5 && $HOME/.bin/screenlogger.sh & even if I would prefere to replace the sleep 5 with waiting for that the X11 server is initialised.
    – Hellfar
    Commented Sep 29, 2016 at 15:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .