Dear call_krushna, dear David the H.!
When I tried to write a reply at work, I was unable to send because of a forgotten password. So some of my stuff is already said by David the H.
My first concern was in deed the use of code tags. When you reply there is the "Go advanced" button. In the editor you get to see there is a "#" button which creates the little helpful code tags. Otherwise you can use David the H.'s way of inserting them directly
I believe the problem is that your posting is not an EXACTLY match of the line in your file due to automated formatting done by LQ. That is why we asked you to post the file once more with code tags. Unless we know the exact content of your file we can not find out, what went wrong with the reg ex. I would assume there is one or more spaces or tabs that are causing trouble.
Quote:
Originally Posted by David the H.
What is this?
Code:
#sed -i /etc/xinetd.d/nrpe -e 's/^\(only_from = 127.0.0.1\)$/\1 10.0.0.120/'
Is that supposed to be the input filename? sed doesn't work that way.
|
Please be assured that I tested my code before posting (mint 12 box: GNU sed-Version 4.2.1). I copy-pasted call_krushnas posting into a file and tested against this file. Everything went well.
Just to be sure I redid my test on a second linux box (suse 10.3: forgot version). Works well too. So I have to admit I am quite a bit confused by that above statement from a senior member.
I know David the H. already made a good proposition, but I want to share the version I made at work anyway. The reason it is still some more complex is that it is appending the new ip after "127.0.0.1" instead of before, although that should not be a matter in your configuration file.
Code:
sed -i /etc/xinetd/nrpe -e 's/\(only_from.*=.*127.0.0.1\)/\1 10.0.0.120/'
I removed the matching for line start and end of line "^" and "$". The ".*" means no or any amount of characters. This reg ex matches EVERY line containing "only_from" followed by "=" and "127.0.0.1".
See if that works for you.
Regards
Heraton
Update:
from man sed
Quote:
sed [OPTION]... {script-only-if-no-other-script} [input-file]...
|
Okay, I get it. The file name is expected to be at the end of the command. But as there was no filename sed seems to have only used the "suffix" as the file name. As I supplied the complete path as suffix it did work anyway. The better way would have been:
Code:
#sed -i -e 's/^\(only_from = 127.0.0.1\)$/\1 10.0.0.120/' /etc/xinetd.d/nrpe
Heraton