By aaronmweiss
I’m looking to develop a script where the Snapshot list is emailed to someone.
When I run doctl compute droplet snapshots $dropletid, I get the following:
ID Name Type Distribution Slug Public Min Disk
61003635 test-droplet_2020-03-22-Sun@17:34-CDT snapshot Ubuntu false 25
61004052 test-droplet_2020-03-22-Sun@17:46-CDT snapshot Ubuntu false 25
61004228 test-droplet_2020-03-22-Sun@17:52-CDT snapshot Ubuntu false 25
61005132 test-droplet_2020-03-22-Sun@18:07-CDT snapshot Ubuntu false 25
61005281 test-droplet_2020-03-22-Sun@18:11-CDT snapshot Ubuntu false 25
61007940 test-droplet_2020-03-22-Sun@19:04-CDT snapshot Ubuntu false 25
However, when I echo that to an email, with this sudo /snap/bin/doctl compute droplet snapshots $dropletid >> $email_notification, I get the following in the email:
ID Name Type Distribution Slug Public Min Disk 61003635 test-droplet_2020-03-22-Sun@17:34-CDT snapshot Ubuntu false 25 61004052 test-droplet_2020-03-22-Sun@17:46-CDT snapshot Ubuntu false 25 61004228 test-droplet_2020-03-22-Sun@17:52-CDT snapshot Ubuntu false 25 61005132 test-droplet_2020-03-22-Sun@18:07-CDT snapshot Ubuntu false 25 61005281 test-droplet_2020-03-22-Sun@18:11-CDT snapshot Ubuntu false 25 61007940 test-droplet_2020-03-22-Sun@19:04-CDT snapshot Ubuntu false 25 61008918 test-droplet_2020-03-22-Sun@19:15-CDT snapshot Ubuntu false 25
Instead of the output being on one line, I want the output to be on as many lines as being requested.
Is there something I’m missing?
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!
Hi there @aaronmweiss,
What I usually would do in this case is save the output in a file, then with send mail you could proceed that file like this:
- sendmail email@yourdomain.com < output_file.txt
You can set your subject as the first line of the file:
Subject: Your mail subject
To save the output to a file it would look something like this:
#!/bin/bash
echo 'Subject: Your mail subject' > ~/output_file.txt
doctl compute droplet snapshots $dropletid >> ~/output_file.txt
sendmail email@yourdomain.com < ~/output_file.txt
To make things more secure rather than having a specific output file, I would recommend using the mktemp command:
#!/bin/bash
temp_output=$(mktemp /tmp/temp-output.XXXXXX)
echo 'Subject: Your mail subject' > ${temp_output}
doctl compute droplet snapshots $dropletid >> ${temp_output}
sendmail email@yourdomain.com < ${temp_output}
rm -f ${temp_output}
That way you would always have a different temp file.
Hope that this helps! Regards, Bobby
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.