New Unix/Linux user - trying to a write a bash script to change the hostname on RHEL
Hi All,
I am new to Unix/Linux and I am currently in the process of learning bash shell script. I am trying to write a script, where a user/root can change the hostname by entering the prompts. The following script is not working, can anyone of you guide/help me in fixing my script. Response will be appreciated. -------------------------------------------------------------------------- #!/bin/bash echo -n "Current host name is :" hostname echo -n "Enter the current hostname :" read current_hostname if [ $current_hostname == `uname -n` ] ; then { echo -n "Enter the new hostname:" read new_hostname sed s/$current_hostname/$new_hostname/g >/tmp/hosts_test sed s/$current_hostname/$new_hostname/g >/tmp/network_test } else echo "You have entered the wrong hostname, Please enter the valid hostname:" fi ------------------------------------------------------------------- Since the script is in testing mode, I copied /etc/hosts and /etc/sysconfig/network to /tmp/. Thanks, *unix* |
Well I am probably not sure about the second echo / read as it seems like a test for the user to read from the screen and then hopefully type in the correct name??
Other than that, are you able to provide more information about: Quote:
Are the wrong files being changed? You need to be a lot more specific as a generic 'not working' is very ambiguous. May I firstly suggest you type each line at the command line and see what happens? (exactly what you have in your script) |
Instead of trying to fix this particular script with high probability for the future questions I suggest you work through this guide about Bash scripting - answers all your questions and then some :)
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html For example user input reading is covered in point 10.1 |
All times are GMT -5. The time now is 08:35 PM. |