Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
12-15-2016, 06:48 PM
|
#1
|
LQ Newbie
Registered: Dec 2016
Posts: 17
Rep: 
|
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:
sudo vi +15 /etc/puppet/puppet.conf
|
to go to the specific line that I need to edit in the puppet configuration file. From there, I need to add the line "server = 'server_hostname'" so that the server's hostname is added to the file. But I don't know how to 1. Get the server's hostname from the script and 2. Add the line in the script that writes "server = server_hostname".
Last edited by johnpedou; 12-15-2016 at 06:50 PM.
|
|
|
12-15-2016, 07:35 PM
|
#2
|
Member
Registered: Dec 2016
Distribution: arch
Posts: 668
Rep: 
|
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
Last edited by TheEzekielProject; 12-15-2016 at 07:36 PM.
|
|
|
12-15-2016, 08:16 PM
|
#3
|
LQ Newbie
Registered: Dec 2016
Posts: 17
Original Poster
Rep: 
|
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:
sed: -e expression #1, char 1: unknown command: `�'
|
|
|
|
12-15-2016, 09:29 PM
|
#4
|
Member
Registered: Dec 2016
Distribution: arch
Posts: 668
Rep: 
|
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
Last edited by TheEzekielProject; 12-15-2016 at 09:39 PM.
|
|
|
12-17-2016, 12:27 AM
|
#5
|
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
|
Quote:
Originally Posted by johnpedou
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:
|
It's formatted correctly. But your copy/paste is adding messed up control characters between windows/mac and the linux terminal.
Try typing it from scratch.
|
|
|
12-17-2016, 04:15 AM
|
#6
|
Member
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 421
Rep:
|
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
|
|
|
12-17-2016, 08:00 PM
|
#7
|
LQ Newbie
Registered: Dec 2016
Posts: 17
Original Poster
Rep: 
|
Quote:
if the user adds/deletes lines then you would end up inserting it in places you don't want to
|
Well that isn't really an issue because this script is set to run automatically when a user starts up their machine so they wouldn't have installed puppet or opened up the configuration file yet. I simply changed it using
Quote:
echo " server = hostname">> etc/puppet/puppet.conf
|
and that ended up working. Thank you everyone for responding
|
|
|
12-17-2016, 08:59 PM
|
#8
|
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
|
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 06:33 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|