How can I run a script that requires root privileges at login of a (or any) user?

I am building an Ubuntu 16.04 Docker image. I need to update the list of libraries with the ldconfig -v command but during the docker build process the hardware is not accessible therefore not all libraries will be added so I would like to run the command at the first login of a user.

Is there a directory maybe, from where scripts are executed at login events? Like /etc/init or /etc/init.d for start up.

  • Not sure what the script should do, so to get this correctly: does this script need to run on first login of either which user, then never again (so in total a single time), on first login per user or everytime the user (any) logs in? All can be done. – Jacob Vlijm Feb 5 '17 at 7:37
  • @JacobVlijm The script would contain a single line of useful code: ldconfig -v. It needs to run at first logon and never again. This is a docker image, with a single user so both options are good: for all users or for this single user, let's say the user peter. – Peter Feb 5 '17 at 12:13
  • 3
    Possible duplicate of Is there a script that runs as root when user logs in? – M. Becerra Feb 5 '17 at 12:46
  • @M.Becerra not exactly, this script only needs to run once. The linked dupe is only one part of that. – Jacob Vlijm Feb 5 '17 at 13:09
  • Hi Peter, re- reading your question, I assume the command is not specific to login, is it? You could make it (as part of a few-lines script) run from rc.local (script &), with the condition a marker file does not exist, make it create the marker on first run. Then it will only run a single time. Would that work? Please mention. – Jacob Vlijm Feb 5 '17 at 14:35

Your Answer

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

Browse other questions tagged or ask your own question.