Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run bash script after login

Tags:

linux

bash

ubuntu

I have a bash script with a series of whiptail menus that allows a user to setup their new system, which is Ubuntu server, with no GUI, just CLI (it's going to be a Virtual Machine image).

I'm already forcing a root login by editing /etc/default/grub and /etc/init/tty1.conf, so the user is dropped directly into the root command prompt. From there the user has to type in ./whiptail.sh to start the script and get the whiptail prompts to further setup their host.

Now, I'd like for my script to be what appears up after the the login occurs instead of the user being dropped to the command prompt. How can I do this?

like image 995
Godzilla74 Avatar asked Aug 18 '16 17:08

Godzilla74


1 Answers

All interactive sessions of bash will read the initialization file ~/.bashrc.

So you can just add the script at the end of the root's .bashrc i.e. /root/.bashrc, assuming the script is executable:

echo '/path/to/whiptail.sh' >>/root/.bashrc

Now the script will be always run when root opens a new interactive shell. If you only want to run while login only, not all all interactive sessions you should rather use ~/.bash_profile/~/.bash_login/~/.profile (the first one available following the order).

like image 161
heemayl Avatar answered Sep 19 '22 16:09

heemayl