Operating System : ubuntu server 10.04
Shell : Bash
Objective : To add a line at the end of another line.
Example:
I want to add a SCGI Mount Point in apache2.conf. Everynew line will have a new value and it has to be below the previous written line.
This is what you'd see at the end of the apache2.conf file after lines and lines of text :
I want to add SCGIMount /RPC3 127.0.0.1:5001 below the SCGIMount /RPC2 127.0.0.1:5000 line. Then in the future, i might add SCGIMount /RPC4 127.0.0.1:5002 below SCGIMount /RPC3 127.0.0.1:5001 and so on.
The script should ask me for the RPC value and the port value and then paste it in the conf file.
Thank you. This works in the terminal perfectly. However, it doesn't seem to work in a bash script. Been messing around with all sorts of way for hours now.
An example :
#!/bin/bash
# Script to add a startup item
username=somethingrandom
cp /etc/init.d/originalfile /etc/init.d/$username
sed 's!changeusername!$username!' /etc/init.d/$username > tempfile
mv tempfile /etc/init.d/$username
chown root:root /etc/init.d/$username
chmod 777 /etc/init.d/$username
I've renamed the file in the script to changeusername so its easier. However it doesn't work with the string $username present. If i were to replace $username with "somethingrandomhere" then it would work. However, i want it to change according to the username that i've given in the script.
(Script has been modified for the thread so it would be less complicated. In the real script, I would be asked to input the username)
Thank you very much. I'm new to shell scripting and this has upped my understanding.
I know the best way is to read the manual but my brain doesn't work that way. I like trying things out and sorting through the errors. That is the learning process for me.
Anyways, thank you jin and everyone who has helped me.