• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

fix

GCP Fix Hosts

December 7, 2021

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

#!/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

127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters
 
10.128.0.30 test.mydomain.com test
10.128.0.30 test.c.project-id.internal test  # Added by Google
169.254.169.254 metadata.google.internal  # Added by Google

127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters 10.128.0.30 test.mydomain.com test 10.128.0.30 test.c.project-id.internal test # Added by Google 169.254.169.254 metadata.google.internal # Added by Google

It adds a proper host entry before the Google entries. /etc/hosts has top to bottom precedence.

Filed Under: Cloud Tagged With: file, fix, gcp, hosts

FFMPEG Fix Audio Sync

June 14, 2020

If you have a video with audio sync issues, you can easily fix it using ffmpeg. It takes 2 inputs: the filename and delay: 0.100 is 100 ms or 0.1 seconds. Output file has -fixed appended to it. It’s fast. Only takes 2-3 seconds to process a 1.5 hour recording.

Here’s the script.

ffmpeg -i livestream.mp4 \
-itsoffset 0.100 \
-i livestream.mp4 \
-map 0:0 -map 1:1 \
-acodec copy \
-vcodec copy \
livestream-fixed.mp4

ffmpeg -i livestream.mp4 \ -itsoffset 0.100 \ -i livestream.mp4 \ -map 0:0 -map 1:1 \ -acodec copy \ -vcodec copy \ livestream-fixed.mp4

Filed Under: Linux Tagged With: audio, delay, ffmpeg, fix, sync

GRUB Fixes

February 15, 2020

This are grub fixes to servers that are not booting up due to improper entries in the grub menu.

grub --batch <<END
root (hd0,0)
setup (hd0,0)
quit
END
#
sed -i 's/dev\/sda/dev\/hda/' /boot/grub/device.map
sed -i 's/(hd0)/(hd0,0)/' /boot/grub/menu.lst

grub --batch <<END root (hd0,0) setup (hd0,0) quit END # sed -i 's/dev\/sda/dev\/hda/' /boot/grub/device.map sed -i 's/(hd0)/(hd0,0)/' /boot/grub/menu.lst

The fix includes replacing (hd0) with (hd0,0) and /dev/sda with /dev/hda.

Filed Under: Linux Tagged With: boot, fix, grub, issues, menu

WordPress Asking for FTP Details

December 26, 2019

If WordPress is asking for FTP details when you’re trying to update a theme, plugin, or WordPress itself, you will need to edit your wp-config.php file to add the following line to your configuration.

define('FS_METHOD','direct');

define('FS_METHOD','direct');

Save the file and try updating again. It shouldn’t ask you for FTP details.

Filed Under: WP Tagged With: config, details, fix, ftp, plugin, theme, update, wordpress

Install AWS CLI on Ubuntu 16.04

August 11, 2019

I ran into an issue with AWS CLI on Ubuntu 16.04. I was getting this error, “AWSHTTPSConnection’ object has no attribute ‘ssl_context” every time I try to do a simple “aws s3 ls” command. So, here’s the fix.

Assuming you installed “awscli” using apt. Go ahead and uninstall it.

apt remove awscli

apt remove awscli

Install awscli using pip instead.

apt install python-pip
pip install awscli
aws --version

apt install python-pip pip install awscli aws --version

If this is a fresh install, you may have to run “aws configure.”

Filed Under: Cloud Tagged With: aws, awshttpsconnection, cli, error, fix, install, pip

  • Home
  • About
  • Archives

Copyright © 2023