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!
Accepted Answer
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.