i have this following code to make droplets (and another shell script code to destroy this droplets), I want to cron this code on the cronjob but failed, can anyone tell me how to cron doctl?
#!/bin/bash
#set environtment variable
database_id=$(<./config/database_ID)
region=sgp1
num_nodes=3
size=db-s-2vcpu-4gb
#create readonly
echo "create readonly on ${database_id}"
for i in {1..10}
do
echo "create db-ro-${i}"
doctl database replica create $database_id db-ro-$i --size db-s-4vcpu-8gb --region $region
done
#resizing database
doctl databases resize $database_id --num-nodes $num_nodes --size $size -v
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
Hi there,
When running scripts from a corn job, you need to make sure that you reference files with their full paths.
I believe that you just need to change this line here:
database_id=$(<./config/database_ID)
To include the full path to your config directory, eg:
database_id=$(</full/path/to/the/config/database_ID)
Let me know how it goes.
Best,
Bobby
You need to use full paths in your scripts rather than relative ones. This could be a problem for the system as it can detect different paths and thus provide different outcomes.
In your case
#!/bin/bash
#set environtment variable
database_id=$(<./config/database_ID)
The database_id should have the full path.
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.