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!
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.