Question

Attempting to run a bash script via user-data on creation isn't working and no logs

On Google/EC2 I run a bash script to setup a server and after reading https://www.digitalocean.com/community/tutorials/an-introduction-to-droplet-metadata it seems like I can do that on DigitalOcean too.

I’m running into an issue though where the script isn’t running however and I can’t find where the logs are. On Google/EC2 they’re in /var/log/messages on CentOS but I couldn’t find anything in there on DO and the install.log files in /root/ don’t have anything about the script either.

The user-data I’m trying to run is:

#!/bin/bash

curl {script url} | sh

If I log into the box and run that curl/pipe it works fine. I’m using the Control Panel to create the droplet. Is there something I’m missing? Thanks!

Show comments

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Thanks for brining this to Q&A. Much easier than going over it 140 chars at a time =)

I would recommend using the following in your user-data when creating the droplet in order to accomplish this:

#cloud-config

runcmd:
  - curl {script url} | sh

Since it is a single line, a full bash script shouldn’t be necessary.

Even I am unable to run the script. I am using API V2

{ “name”: “example.com”, “region”: “nyc3”, “size”: “s-1vcpu-1gb”, “image”: “ubuntu-16-04-x64”, “ssh_keys”: null, “backups”: false, “ipv6”: false, “user_data”: “#cloud-config runcmd: - curl <URL> | sh”, “private_networking”: null, “volumes”: null, “tags”: [ “web” ] }

Please help me regarding what am I doing wrong here?

have to say via api I made the mistake of using the field user-data rather than the correct one which is user_data . Once I realised this it worked!!! might help somebody…