Godzilla74 Godzilla74 - 3 months ago 18
Linux Question

Run bash script after login

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?

Answer

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).

Comments