This question has been asked numerous times but for some reason, none of the solutions proposed worked for me. I just want to run a simple script after the user has logged in.

Here are my attempts:

  • I have tried putting the script in /etc/init.d/ and making a symlink in /etc/rc0.d.
  • I tried scheduling it using the @reboot in crontab (crontab -e). Annoyingly, @reboot does not seem to work in Ubuntu(?). I tried this simple line@reboot echo "hi there" to no avail.
  • I tried putting it into the root's crontab(sudo crontab -e) but still nothing happened. Also a simple echo in this crontab does not work too.
  • I also tried to use the @reboot syntax suggested here (@reboot root /home/me/Desktop/script.sh)
  • Followed this and placed the path of the script in /etc/rc.local


  • I'm using Ubuntu 14.04
  • home is mounted, but I also tried my attempts in a VM where home is not mounted
  • I only want to run the script after the user has logged in
  • Nothing fancy about the script it just echoes "hello world"
  • Do you need to run it at a specific runlevel? Do you need to run it in a terminal?
    – kos
    Jul 25, 2015 at 1:23
  • @kos I guess not, it's just a simple attempt of running a script at startup, it only contains an echo
    – krato
    Jul 25, 2015 at 1:23
  • 1
    I guess you want a terminal to see the output of the script, that's the only problem; the only hack I've ever managed to come up with (at least using gnome-terminal or mate-terminal) is this; change mate-terminal to gnome-terminal and remove sudo -H, and obviously change the chain of commands to just echo hello world
    – kos
    Jul 25, 2015 at 1:46
  • If you don't need to output to a TTY there are way nicer solution; probably at least some of the methods you've tried worked already, you just couldn't catch the output since the script is not run in a terminal.
    – kos
    Jul 25, 2015 at 1:48
  • 1
    Not on Ubuntu right now, however notify-send 'hello world' should be enough; create a text file named, say, script.sh, say, in ~/; then add a shebang to the start of the file (#!/bin/bash) and the command on the next line; mark the script as executable by running chmod +x ~/script.sh and add an entry to Startup Applications to call it; the command would be simply the path to the script, i.e. ~/script.sh
    – kos
    Jul 25, 2015 at 2:30

1 Answer 1


The standard location for a script that must run at login is /etc/profile. It will then run for every user (once) when they log in. The user never gets to see the output of the script, it is logged

If it is only for a specific user, it should be added to .profile in their home directory.

With login I mean when you enter your username and password.

Any errors normally show up in ~/.xsession-errors

If it has to run every time you open a terminal window, it should be added to /etc/bash.bashrc or to .bashrc in the user's home directory.

At work, I mount a number of network shares when I log in. This is done in .profile in my home directory (it needs only to be done once).

Every time I open a terminal window I get a fortune cookie. This happens because the last line in .bashrc in my home directory contains fortune.

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.