Report this

What is the reason for this report?

“user_data” script can't run a sed command

Posted on September 28, 2019

I am creating a DigitalOcean droplet through their API. I am using their “user_data” feature to run commands upon creation.

This issue is that the “sed” command doesn’t work for this, and I can’t understand why. It works perfectly fine if you enter the command through the command line, but not in the script.

The code below is what I am using. Don’t mind the \' I am using PHP so I have to include those.

Anyways, I know that the script is running because the “installed” file is being created successfully. It’s just that the sed command isn’t running for some reason.

'user_data' => '                    
#cloud-config
runcmd:
- sed \'/DB_DATABASE/s/=.*/=test/g\' /var/www/html/app/.env
- sed \'/DB_USERNAME/s/=.*/=test/g\' /var/www/html/app/.env
- sed \'/DB_PASSWORD/s/=.*/=test/g\' /var/www/html/app/.env
- touch /var/www/html/app/storage/installed
'

The expected outcome is for the sed commands to work and change the values accordingly. The actual result is that the command isn’t ran, or just doesn’t work.

If you need more information please let me know!

Thank you



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
0

Hello, @Rainn

Looking at this I can see that you’re not using any options for the sed command itself. Usually the -i option should change the data for you, so it will be sed -i

Let me know how this goes.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.