简体   繁体   中英

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?

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

If you want it to be global , add you script to

/etc/profile 

If you want it to be user-specific , add you script to

/home/$USER/.profile

Consider upvoting the original answer here: https://unix.stackexchange.com/a/56088/343022

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM