I have several machines and the hostnames are really long.. i.e. companyname-ux-staging-web1.companyname.com. So my prompt looks something like
[root@mycompany-ux-staging-web1 ~]#
I'd like to shorten that up for all users on all machines with the least amount of work. From what I read I have a couple options, but they all have their drawbacks.
I could change the hostname, but that would likely affect applications. Not a great choice.
I could alter also $PS1 at login for all users by editing all .bashrc for existing users, and edit /etc/skel/.bashrc for potential new users. That's a lot of work across >10 machines.
What's my best option or what have I overlooked?
You should probably export PS1. Instead of editing a user's bashrc, you should edit the system bashrc: a user should be able to override a prompt with their choice.
Secondly, to distribute the file use either scp or clusterssh. If you set up a rsa key you don't even need to enter your password more than once for scp:
you can create an executable script in the directory /etc/profile.d/, for example: /etc/profile.d/custom_prompt.sh, with this content:
With this method, you don’t need to modify any file in order to change the bash prompt for all the users.
It shouldn't be any more work than any existing configuration management you're using to deploy new configurations across these ten servers. If this is a persistent problem for your organization, you definitely want to look into a configuration management tool like Puppet/Chef/Cfengine and a deployment tool like MCollective/RunDeck/Capistrano/Fabric.
Edit /etc/profile
/etc/profile is run when a user logs in. ~/.bashrc is run for other shells (e.g. opening an xterm)
export PS1="[\e[0;35m][\u \t \h \W]\$ [\e[0m]"
You probably will want to take out the \h
https://wiki.archlinux.org/index.php/Color_Bash_Prompt
You could edit the system wide bashrc in /etc/bashrc but that is easily overwritten by any user with shell access. You could pretty easily script something to push out a new .bashrc for a user list using scp.
As stated scp is probably the easiest with a simple script. Another option is rysnc. Also, you can just cron to do it with sshkeys.
Your second option seems feasible if you can send commands to all the servers at once to update files. For this you could use pssh on linux (http://code.google.com/p/parallel-ssh/) or PuTTY Command Sender (http://www.millardsoftware.com/puttycs) with PuTTY on Windows.
You could build a sed/awk command that could replace the line in the skel .bashrc and /etc/bashrc and users bashrc files. Then send this as one command to all the systems.
The sed command is going to likely be the most work. Unfortunately, I am not as good with sed and awk. Someone else may be able to offer more insight in this area. Hope this information helps!
I had to do this for multiple ubuntu servers and for all users, I wanted to have the full FQDN on the prompt instead of just the hostname (the opposite of what you were doing). I found that changing /etc/bash.bashrc is not enough. I also tried fiddling with diffent profile.d files but it was useless because the home .bashrc is always applied last.
What I ended up doing was pushing the below script with ansible to all servers and that did the trick for all users and for all future applications.