gcp activate service account

How to activate a GCP service account for other users in Linux. First generate a key for the service account. Save as key.json. Login to the server as that user and copy the key there. Activate the service account. $ gcloud auth activate-service-account [ACCOUNT] --key-file=key.json Once authenticated, you should be able to check if service account is active. $ gcloud config list A better option without needing a key. gcloud config set core/account service-account@project-id.iam.gserviceaccount.com

December 10, 2021 · 1 min · ulysses

github generate a key

Generate a ssh key for Github ssh-keygen -t ed25519 -C "your_email@example.com" Copy and paste the ‘id_ed25519.pub’ key to Github. cd .ssh $ ls -l -rw-r--r-- 1 ulysses ulysses 537 Jul 14 12:54 id_ed25519 -rw-r--r-- 1 ulysses ulysses 194 Jul 14 12:54 id_ed25519.pub Go to Settings > SSH and GPG keys. Add new SSH key and authorize. You can then clone using the SSH format. $ git init $ git clone git@github.com:acoount/repo.git

December 10, 2021 · 1 min · ulysses

docker ps

Check Docker running processes. $ docker ps -a To see it in real time. $ watch docker ps

December 9, 2021 · 1 min · ulysses

gcp spot vm

Spot VMs are preemtible, they can be reclaimed by the Cloud provider. However you can get deep discounts using them. Launch a spot instance in GCP using Terraform. provider "google" { project = "airy-totality-151318" zone = "us-central1-c" } resource "google_compute_instance" "test" { name = "test" machine_type = "e2-micro" boot_disk { initialize_params { image = "debian-cloud/debian-9" } } scheduling { preemptible = true automatic_restart = false } network_interface { network = "default" access_config { } } }

December 8, 2021 · 1 min · ulysses

gcp fix hosts

This is a script that fixes /etc/hosts in GCP. #!/bin/bash # VARIABLES FILE='/etc/hosts' #BACKUP /etc/hosts before changes cp -ipHR $FILE $FILE_$(date +%Y-%m-%d_%H-%M-%S) # GET IP ADDRESS IP=$(/sbin/ifconfig | grep 'inet' | grep -v 'inet6' | grep -v '127.0' | cut -d: -f2 | awk '{print $2}' | head -1) # GET HOSTNAME HN=$(/bin/hostname) # GET PROJECT ID echo "169.254.169.254 metadata.google.internal # Added by Google" >> $FILE PR=$(curl -f -s http://metadata.google.internal/computeMetadata/v1/project/project-id -H "Metadata-Flavor: Google") # ADD HOSTNAME ENTRY TO /etc/hosts STRING="$IP $HN.mydomain.com" if grep -q "$STRING" "$FILE" then echo "Valid host entry." else echo "Adding host entry." echo $STRING $HN >> $FILE fi # DELETE GOOGLE ENTRIES. sed -i '/# Added by Google/d' $FILE # ADD BACK GOOGLE ENTRIES. echo $IP $HN".c."$PR".internal" $HN" # Added by Google" >> $FILE echo "169.254.169.254 metadata.google.internal # Added by Google" >> $FILE # SET PERMISSIONS. chmod 644 $FILE # DISPLAY /etc/hosts cat $FILE Result ...

December 7, 2021 · 1 min · ulysses

fibonacci sequence in python

How to calculate Fibonacci sequence in Python. Create a file called fib.py. nterms = int(input("How many terms? ")) n1, n2 = 0, 1 count = 0 if nterms Run it. $ python fib.py How many terms? 5 Fibonacci sequence: 0 1 1 2 3 Again. $ python fib.py How many terms? 10 Fibonacci sequence: 0 1 1 2 3 5 8 13 21 34

December 3, 2021 · 1 min · ulysses

aws display lightsail snapshots

How to display Lightsail snapshots. #!/bin/bash displaysnapshots () { echo '--------------------------------------------------------' aws lightsail get-instance-snapshots --query 'instanceSnapshots[].[name]' --output text | sort echo '--------------------------------------------------------' } displaysnapshots Result. daily_ulyme_1637812801 daily_ulyme_1637899201 daily_ulyme_1637985601 daily_ulyme_1638072001 Adding timestamp to the output. aws lightsail get-instance-snapshots --query 'instanceSnapshots[].[name,createdAt]' --output text | sort Result. daily_ulyme_1637812801 1637812806.853 daily_ulyme_1637899201 1637899208.285 daily_ulyme_1637985601 1637985606.184 daily_ulyme_1638072001 1638072006.579 Convert Unix timestamp to iso8601. Edit your ~/.aws/config file. Add this line. cli_timestamp_format = iso8601 Result. daily_ulyme_1637812801 2021-11-25T04:00:06.853000+00:00 daily_ulyme_1637899201 2021-11-26T04:00:08.285000+00:00 daily_ulyme_1637985601 2021-11-27T04:00:06.184000+00:00 daily_ulyme_1638072001 2021-11-28T04:00:06.579000+00:00

December 1, 2021 · 1 min · ulysses

bash input executes functions

How to execute functions in Bash based on argument. There are 2 functions: build and terminate. #!/bin/bash build () { echo 'Building services' } terminate () { echo 'Terminating services' } if [ $1 == 'build' ]; then build elif [ $1 == 'terminate' ]; then terminate else echo 'Valid options are "build" or "terminate"' fi Execute a function based on argument. $ bash test.sh build Building services $ bash test.sh terminate Terminating services $ bash test.sh anyother Valid options are "build" or "terminate"

December 1, 2021 · 1 min · ulysses

bash read file

How to read a file line by line in Bash. #!/bin/bash file=test.txt while IFS= read -r line; do echo $line done Contents of test.txt. one two three Results when running test.sh. $ bash test.sh one two three To read multiple strings line by line. #!/bin/bash file=test.txt while read -r a b; do echo $b done Modified contents of test.txt. one 1 two 2 three 3 New results. $ bash test.sh 1 2 3

December 1, 2021 · 1 min · ulysses

delete lines using sed

How to delete a line containing a pattern using sed. Contents of test.txt. $ cat test.txt one two three Delete a line matching the string “one.” sed -i '/one/d' test.txt Display test.txt $ cat test.txt two three

December 1, 2021 · 1 min · ulysses