Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
1  
you didn't tell us what distro. distro's have gone to great effort to build a combination of standards, conventions, and customization points around shell environments. whatever you wind up doing, make sure you're working with your distro not against it. –  cagenut Jan 4 '11 at 18:36
add comment

6 Answers

up vote 5 down vote accepted

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:

eval `ssh-agent`
ssh-add
for h in `cat ~/hostlist`; do
    scp ~/newbashrc ${h}:/etc/bashrc
done
eval `ssh-agent -k`
share|improve this answer
    
This answers my question. Thank you. –  incredimike Jan 4 '11 at 19:23
add comment

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.

share|improve this answer
    
+1 I agree with your suggestion for using puppet although the upfront "cost" would be greater than just editing the ten machines by hand if all incredimike wants to do is shorten the hostname. But going forward, the continual update and management time of 10+ servers is greatly reduced with Puppet. I'm using it to manage 200+ servers and am pretty happy with it. –  Patrick R Jan 4 '11 at 18:41
    
Yes, I also +1 this as I will be setting up puppet in the future to streamline management and help ensure machine state but, as Patrick suggests, the upfront cost is too high to set it up right now. –  incredimike Jan 4 '11 at 19:22
add comment

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.

share|improve this answer
1  
I'm not sure it's all that advisable to overwrite the user's settings in this case. If the user wants a longer $PS1, why not? It's a bad precedent to edit anything in a user's home directory. –  Ben Cotton Jan 4 '11 at 18:59
add comment

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

  • \u: Display the current username
  • \h: Display the hostname
  • \W: Print the current working directory
  • \H: Display FQDN hostname
  • \@: Display current time in 12-hour am/pm format
  • \t: the current time in 24-hour HH:MM:SS format
  • \e: an ASCII escape character (033)

https://wiki.archlinux.org/index.php/Color_Bash_Prompt

share|improve this answer
add comment

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!

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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.