0

I am writing a code that will change the IP of VestaCP panel automatically. I need the code to replace the variable $oldIP with a new variable $newIP, so I wrote this piece of code.

sudo perl -pi -e 's/${oldIP}/${newIP}/g' /etc/nginx/conf.d/${oldIP}.conf

But the code doesn't replace the oldIP from oldIP.conf (123.123.123.123.conf).

However, if I try

sudo perl -pi -e 's/123.123.123.123/123.456.123.456/g' /etc/nginx/conf.d/123.123.123.123.conf

It works flawlessly, although I can't use this code since ever servers have a different IP and I can't predict the next IP when it changes.

What am I doing wrong here? Any solutions? Thanks in advance!

P.S. If it helps to know, I am on Ubuntu 16.04.

1 Answer 1

3

Your variables are not expanded between single quotes. Use double quotes instead:

sudo perl -pi -e "s/${oldIP}/${newIP}/g" /etc/nginx/conf.d/${oldIP}.conf
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much! That solved my problem. I can't believe I made that stupid mistake lol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.