• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Search

Linux

Capture GCP VM Serial Port Output to Terminal

August 28, 2023

Here’s the command to capture a GCP VM serial port output to your terminal.

gcloud compute instances get-serial-port-output servername \
--zone us-central1-f \
--project your-project \
--port 1

gcloud compute instances get-serial-port-output servername \ --zone us-central1-f \ --project your-project \ --port 1

You can also send the output to a file.

gcloud compute instances get-serial-port-output servername \
--zone us-central1-f \
--project your-project \
--port 1 > output.txt

gcloud compute instances get-serial-port-output servername \ --zone us-central1-f \ --project your-project \ --port 1 > output.txt

Filed Under: Cloud, Linux Tagged With: file, gcp, output, send, serial port, terminal

GCP VM Breakglass SSH

August 28, 2023

When you exhausted all efforts trying to login to a VM and there’s no other way to log in to the server, here’s a breakglass method to allow you to log in to a VM via a startup script. Just add the following bash script to the VM startup section. Change the username and password to your liking. Restart the server to trigger the startup script. After reboot, it should give you access to the server. In addition, you will also have sudo access so you can switch as root.

1. Edit the VM.
2. Go to the Startup script section and add the following.

#!/bin/bash
user="johndoe"
pass="password"
if id $user >/dev/null 2>&1; then
    exit
else
    adduser 
    echo $user:$pass | chpasswd
    usermod -aG google-sudoers $user
fi

#!/bin/bash user="johndoe" pass="password" if id $user >/dev/null 2>&1; then exit else adduser echo $user:$pass | chpasswd usermod -aG google-sudoers $user fi

3. Restart the server.
4. Log in as user.
5. Fix the login issue.
6. Remove user.
7. Remove the startup script.

Filed Under: Cloud, Linux Tagged With: breakglass, gcp, ssh, vm

Mac vs Linux Date

August 17, 2023

Converting Mac and Linux Dates

Linux

#!/bin/bash
start_time=$(date +%s)
log=$(date -d @$start_time +%Y%m%d-%H%M%S) 
start=$(date -d @$start_time)
echo $start_time
echo $log
echo $start
sleep 10
stop_time=$(date +%s)
stop=$(date -d @$stop_time)
echo $stop_time
echo $stop

#!/bin/bash start_time=$(date +%s) log=$(date -d @$start_time +%Y%m%d-%H%M%S) start=$(date -d @$start_time) echo $start_time echo $log echo $start sleep 10 stop_time=$(date +%s) stop=$(date -d @$stop_time) echo $stop_time echo $stop

Mac

#!/bin/bash
start_time=$(date +%s)
log=$(date -r $start_time +%Y%m%d-%H%M%S) 
start=$(date -r $start_time)
echo $start_time
echo $log
echo $start
sleep 10
stop_time=$(date +%s)
stop=$(date -r $stop_time)
echo $stop_time
echo $stop

#!/bin/bash start_time=$(date +%s) log=$(date -r $start_time +%Y%m%d-%H%M%S) start=$(date -r $start_time) echo $start_time echo $log echo $start sleep 10 stop_time=$(date +%s) stop=$(date -r $stop_time) echo $stop_time echo $stop

Same output for both

1692292771
20230817-171931
Thu Aug 17 05:19:31 PM UTC 2023
1692292781
Thu Aug 17 05:19:41 PM UTC 2023

1692292771 20230817-171931 Thu Aug 17 05:19:31 PM UTC 2023 1692292781 Thu Aug 17 05:19:41 PM UTC 2023

Filed Under: Linux Tagged With: date, differences, format, linux, mac

  • « Go to Previous Page
  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to page 4
  • Go to page 5
  • Interim pages omitted …
  • Go to page 166
  • Go to Next Page »
  • Home
  • About
  • Search

Copyright © 2023