Report this

What is the reason for this report?

execute doctl using cronjob + shell script failed

Posted on November 26, 2022

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!

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.

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

Hi @sleepingseagreenmorel,

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.

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.