Connecting to Puppet Server with Shell Scripting
Hello, I am trying to write a shell script that will automatically install puppet agent and then connect to the puppet host. I was able to successfully get the script to install puppet. However, I am currently stuck because I don't know how to write part of the script to edit the puppet.conf file.
I wrote the line Quote:
|
As far as writing to the file, this sounds like a job for sed
e.g. sed -i ‘15iserver = server_hostname’ FILE -i means modify the specified file in place, the 15i inserts "server = server_hostname" at line 15. as far as grabbing the name from the script i imagine youd just have to store the hostname as a variable somewhere to grab it from later. Im no expert so please take that advice with a grain of salt lol |
Thank you for your response. I believe you were correct with the command sed. But I don't think the one you posted was formatted correctly. When I put it into my script and ran it, I got an error:
Quote:
|
Try more like sed -i '15iserver=server_hostname' FILE
This worked on my file as long as there is there at least >= as the line at which you are trying to insert. sed doesn't seem to like my spaces. I'm not super familiar with the command, only light use. Note that this will print literally server=server_hostname on line 15. I'm not exactly sure how you would pull that variable in though. I think that is probably a job for echo but again I'm not super familiar with it yet either haha |
Quote:
Try typing it from scratch. |
Problem with using 'line 15' as basis for the insertion, is that it is arbitrary. There is a high chance that if the user adds/deletes lines then you would end up inserting it in places you don't want to. Instead, you can use some familiar lines like certname or environment to base it from. For example:
Code:
sed -i '/^\s*certname/a \\tserver = server_hostname' puppet.conf |
Quote:
Quote:
|
Was it because you typed it in instead of copy/pasted?
If so, there are usually changes you can make to your emulator/shell/editor that will cause it to refuckulate correctly and stop causing \r and ^M pasting errors. If that is something you want to figure out, start a new thread and let us know your OS, text editor and shell, and we could help out. Good luck! |
All times are GMT -5. The time now is 02:45 AM. |