Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to run a script on login irrespective of the shell? I would like to have something on the lines of the ssh login to an Ubuntu server - which displays the free RAM etc.

I understand that the welcome message itself is in /etc/motd, but the file seems to update on each login. How is this done? I do not want to use ~/.bashrc or ~/.profile and would like to have one for all users in the system by default.

share|improve this question
What sort of login? Graphical or terminal/SSH? – Oli Apr 4 '12 at 14:47
Terminal Logins. I was thinking of adding a script to /etc/profile.d/ This ececutes after the message from /etc/motd is displayed. – Lord Loh. Apr 4 '12 at 16:18
up vote 2 down vote accepted

Since you are asking for a "run for each login" versus "run at boot", this may be of help.

in the file /etc/login.defs search for "fakeshell" Here is the comment text for that parameter:

 # Instead of the real user shell, the program specified by this parameter
 # will be launched, although its visible name (argv[0]) will be the shell's.
 # The program may do whatever it wants (logging, additional authentification,
 # banner, ...) before running the actual shell.
 # FAKE_SHELL /bin/fakeshell

Be careful about any assumptions for your environment when using this approach. Define all your own paths for executables and data.

share|improve this answer
Thank you. I added a line FAKE_SHELL /etc/loginscript and added a shell script with execute permissions for all. But nothing happened on login through ssh :-( – Lord Loh. Apr 4 '12 at 16:01
I was thinking of adding a script to /etc/profile.d/ This executes after the message from /etc/motd is displayed. – Lord Loh. Apr 4 '12 at 16:18
Sorry that did not work. I just re-read your request and wonder if I misunderstood. Are trying to create a script that any user can run that gives free RAM and other system statistics? I was trying to find an answer for the "run this script for all users when they log in". If you want something for all you can create a special account, call it "sysres" that has no password but instead of a shell it just runs the loginscript to display what you want, and then it exits, no interaction provided. I will still look for a "runs for every user, every login, and style" answer. – Hey Gary Apr 5 '12 at 4:29
I was wondering how ubuntu displays system statistics. Apparently, it seems to run a script to update /etc/motd and the statistics is displayed as a welcome message. – Lord Loh. Apr 6 '12 at 19:13
I now realize that the FAKE SHELL was running a script, but only at the tty and not at the pty (ssh). And running a bash script that did not transfer over to bash caused me to be logged out immediately after logging in and running the script. – Lord Loh. Apr 7 '12 at 6:06

You can use /etc/rc.local

rc.local is executed after all other init stuff is over - the last step in the startup process. It's really intended for local machine init stuff outside of the System V init (i.e. outside of the runlevel scripts).

share|improve this answer
Should point out that this happens before any sort of graphical login; even before X has even started to load and only happens at boot (not once per login). – Oli Apr 4 '12 at 14:42

I you are looking for a script that display's Ram, HDD usage, IP address then I would suggest installing landscape-common:

sudo apt-get update
sudo apt-get install landscape-common

Then adding an alias in .bashrc which reflects something like alias lsi='landscape-sysinfo' when you run it you get the following info:

System load:  2.7                Processes:             161
  Usage of /:   8.3% of 135.63GB   Users logged in:       1
  Memory usage: 19%                IP address for eth0:
  Swap usage:   0%                 IP address for virbr0:

Graph this data and manage this system at []
share|improve this answer
This is not what I am looking for. I was trying to run a script before any TTY prompt showd up. Ubuntu happens to display statistics by default (from /etc/motd) and I used that as an example. I am really interested in knowing how /etc/motd is updated every time someone logs in. – Lord Loh. Jul 30 '12 at 21:47

Your Answer


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.