bash convert bytes

Here’s a function to convert bytes into kilo, mega, giga, tera up to zeta bytes. function convert_bytes { bytes=$credits b=${bytes:-0}; d=''; s=0; S=(Bytes {K,M,G,T,E,P,Y,Z}B) while ((b > 1024)); do d="$(printf ".%02d" $((b % 1000 * 100 / 1000)))" b=$((b / 1000)) let s++ done echo "$b$d ${S[$s]}" } credits=2308974418330 echo $credits convert_bytes $credits Result is: 2308974418330 2.30 TB

January 26, 2020 · 1 min · ulysses

tasksel lampserver

Tasksel is a Debian/Ubuntu tool that installs multiple related packages as a co-ordinated “task” onto your system. It’s similar to meta-packages where tasks are dericed from from Ubuntu package managers like Synaptic or KPackageKit. Here’s a quickway to install a lamp server. # install tasksel first if you don't have it. apt install tasksel # install a lamp server package tasksel install lamp-server

January 24, 2020 · 1 min · ulysses

wordpress salt

Here’s a quick way to autogenerate salt for WordPress. curl -s https://api.wordpress.org/secret-key/1.1/salt/

January 24, 2020 · 1 min · ulysses

google sdk install on debian or ubuntu

Here’s the script. echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] \ https://packages.cloud.google.com/apt cloud-sdk main" | \ sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list sudo apt-get install apt-transport-https ca-certificates sudo curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | \ sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - sudo apt-get update && sudo apt-get install google-cloud-sdk

January 23, 2020 · 1 min · ulysses

aws display iam certificates

SSL certificates were uploaded to IAM prior to Certificate Manager. Unfortunately, the certificates are not visible from the IAM console. There’s no way to view when a certificate is expiring. So, here’s how to display IAM certificates from the AWS CLI. aws iam list-server-certificates

January 22, 2020 · 1 min · ulysses

determine usb format type

Here’s how to determine what type of USB format a thumb drive is in Linux. df -Th (shows the file system type) lsblk (shows the block devices) lsusb (show usb ports and devices) fdisk -l (displays the USB format type) To display, use “fdisk -l” to display either NTFS, FAT32 or exFAT32.

January 21, 2020 · 1 min · ulysses

linux prompt

Here’s my favorite Linux prompt. PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' Add to end of your .bashrc to make it permanent.

January 20, 2020 · 1 min · ulysses

gcp start multiple instances

Here’s how to start multiple instances using Bash and Google SDK. #!/bin/bash while IFS=', ' read -r a b c; do instance="${a//[[:blank:]]/}" project="${b//[[:blank:]]/}" zone="${c//[[:blank:]]/}" echo "Starting $instance ...." gcloud compute instances start $instance \ --zone $zone --project $project --async done Instances are read from an external file. The file format is displayed below. server1,project1,us-central1-a server2,project2,us-central1-b server3,project3,us-central1-c To stop multiple instances, replace “start” with “stop.”

January 19, 2020 · 1 min · ulysses

gcp check instances running

Here’s how to check if instances are running in GCP. #!/bin/bash while IFS=', ' read -r a b c; do instance="${a//[[:blank:]]/}" project="${b//[[:blank:]]/}" zone="${c//[[:blank:]]/}" gcloud compute instances describe $instance \ --zone $zone --project $project \ --format='table[no-heading](name,status,zone)' done Instances are read from an external file. File is comma delimited with instance name, project id and zone data.

January 18, 2020 · 1 min · ulysses

terraform first class expressions

If you were running the older versions of Terraform, with release 0.12 and higher, there will be certain parts of your script that are no longer supported. Terraform uses expressions for dynamic configuration and dependencies. First-class expressions enable variables and operations to be performed outside of strings. In Terraform 0.11 and earlier all expressions were required to be part of interpolations in existing strings, such as “${var.foo}. In Terraform 0.11. ...

January 16, 2020 · 1 min · ulysses