Welcome
My name is Ulysses. Sr. Cloud Engineer at Cardinal Health.
About This Website
This is my static site based on Hugo.
My name is Ulysses. Sr. Cloud Engineer at Cardinal Health.
This is my static site based on Hugo.
If your Bash script calls for 3 arguments, here’s how to check it. if [ "$#" -ne 3 ] then echo "Usage: ./script.sh project diskname policy" exit fi You can adjust -ne 3 to any number based on the number of required arguments.
When displaying in a time format, it’s best to display numbers below 10 with leading zeros. Here’s a nice function you can call to covert numbers below 10. convert () { # print the number as a string with a leading zero number=$(printf '%02d\n' "$1") echo $number } convert 5 Result 05
If you want to create dummy files, there’s a faster command than ‘dd’ called ‘fallocate.’ Create a 30GB called temp_30GB_file. fallocate -l 30G temp_30GB_file Unlike dd which can take minutes depending on file size, fallocate is instantaneous.
Just a few things about Bash variables. Every variable in Bash is global and are accessible anywhere in the script. They can be used in a function, loop, or conditional statement within the script. # setting a variable a = "hello" # printing a variable echo $a # using a variable inside a function hello_function () { echo $a } # passing a variable to a function hello_function $a
Another time saving command if you want to clear the entire line on a terminal is Ctrl+K. Ctrl+K
If a command is too long, you can move your cursor to the beginning or the end of the line. Move to start of the line. ctrl+A Move to end of the line. ctrl+E
How to merge several PDFs into one file. Install apt install poppler-utils Merging PDF files pdfunite one.pdf two.pdf three.pdf output.pdf
Here’s how to display GCP VM labels. Display all labels. gcloud compute instances describe VM --zone ZONE --project PROJECT_ID --format="value(labels)" Display a specific label. gcloud compute instances describe VM --zone ZONE --project PROJECT_ID --format="value(labels.key)"
Here’s how to run Debian on a Docker container. docker pull debian docker run -it debian /bin/bash
Here’s how to add labels to snapshots. It will cycle through from a list of disks. #!/bin/bash ts=$(date +%Y%m%d-%H%M%S) log="add-labels-logs-$ts" >$log disks='manual-disks.txt' now=$(date +%s) epoch=$(date +%s -d "+14 days") while read -r project snapshot; do echo "Project: $project" gcloud compute snapshots add-labels $snapshot --labels=delete-after=$epoch --project $project done