Update my.cnf auto_increment_offset with last character of hostname?

Simplified your command a bit, this one works for me.

Up vote 1 down vote favorite share g+ share fb share tw.

I need to take the hostname of the machine and grab the last character. In this example the hostname is: web-01 I want to get the "1" from the hostname. This command will also be used on web-02, etc. I have this working pretty well with: hostname | awk '{print substr($0,length,1)}' After I get that number I need to update a file.

In this case I need to update the following line: auto_increment_offset = 0 And it should become: auto_increment_offset = I was attempting to do this portion with: sed -i "/^auto_increment_offset/s/0/$1/" /etc/mysql/conf. D/my. Cnf; Full command I am attempting to run: hostname | awk '{print substr($0,length,1)}' | sed -i "/^auto_increment_offset/s/0/$1/" /etc/mysql/conf.

D/my. Cnf For some reason it isn't working and I need to step-out for a bit, so I figured I would ask for help. That's it.

Please inform me that I am an idiot and assist me in making this work. Thanks for your help. Bash sed awk link|improve this question edited Mar 12 at 2:11 asked Mar 11 at 21:09stevek1977194.

Simplified your command a bit, this one works for me: sed "/^auto_increment_offset/s/=. */= ${HOSTNAME#${HOSTNAME%? }}/" /etc/mysql/conf.

D/my.cnf.

You are my favorite person. Thank you very much. I love the simplification.

I knew there was a better way to go about it and you nailed it. Thx. – stevek1977 Mar 12 at 2:10 You're welcome.

– Gergo Erdosi Mar 12 at 7:36.

This may be what you're looking for... I just took what you wrote, and wrote some sed inside sed. I often use this sort of trick to work around similar problems - even if it's not very succinct. Otherwise gergoerdosi's answer is nicer imo.

Hostname | awk '{print substr($0,length,1)}' | sed -e "s%\(.*\)%sed -i \"/^auto_increment_offset/s/0/\1/\" /etc/mysql/conf. D/my. Cnf %" | sh.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions