• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

Archives for May 2020

FFMPEG Convert MP3 to OGG

May 31, 2020

How to convert MP3 to OGG audio format.

ffmpeg -i in.mp3 -ar 48000 -vn -c:a libvorbis out.ogg

ffmpeg -i in.mp3 -ar 48000 -vn -c:a libvorbis out.ogg

If you have sample rate errors, use -vn.

Filed Under: Linux Tagged With: convert, ffmpeg, mp3, ogg, rate, sample

GCP Create Firewall with Tags

May 28, 2020

Here’s another way to create a firewall in GCP using network tag as targets.

gcloud compute firewall-rules create "firewall-name" \
    --description="egress rule to allow port 8000 to destination" \
    --priority "1000" \
    --direction EGRESS \
    --action allow \
    --network "your-network" \
    --target-tags="your-network-tag" \
    --destination-ranges="10.0.0.1/32" \
    --rules tcp:8000

gcloud compute firewall-rules create "firewall-name" \ --description="egress rule to allow port 8000 to destination" \ --priority "1000" \ --direction EGRESS \ --action allow \ --network "your-network" \ --target-tags="your-network-tag" \ --destination-ranges="10.0.0.1/32" \ --rules tcp:8000

Filed Under: Cloud Tagged With: destination, egress, firewall, gcp, tags, target

EC2 Password Authentication

May 18, 2020

When you stand up an AWS instance, it’s only accessible via SSH key using the default user, typically ec2-user.

Add password to ec2-user, then enable password authentication to ‘yes’ in SSH.

# Add password to ec2-user
sudo passwd ec2-user
# edit ssh config
vim /etc/ssh/sshd_config
# enable password authentication
PasswordAuthentication yes
# save file and exit

# Add password to ec2-user sudo passwd ec2-user # edit ssh config vim /etc/ssh/sshd_config # enable password authentication PasswordAuthentication yes # save file and exit

Restart SSH service.

systemctl restart sshd.service

systemctl restart sshd.service

Filed Under: Cloud, Linux Tagged With: authentication, aws, ec2, keys, password, ssh

GCE Agent Bash

May 11, 2020

This is a Bash script to restart a service.

#!/bin/bash
 
SERVICE=google_osconfig_agent
AGENT=google-osconfig-agent
 
if (( $(ps -ef | grep -v grep | grep $SERVICE | wc -l) > 0 ))
then
    echo "$AGENT service running, everything is fine"
else
    echo "$AGENT is not running"
    echo "Restarting service"
    systemctl start $AGENT
    sleep 5s
    if (( $(ps -ef | grep -v grep | grep $SERVICE | wc -l) > 0 ))
    then
      sleep 2s
      echo "$AGENT service is now running"
    fi
fi

#!/bin/bash SERVICE=google_osconfig_agent AGENT=google-osconfig-agent if (( $(ps -ef | grep -v grep | grep $SERVICE | wc -l) > 0 )) then echo "$AGENT service running, everything is fine" else echo "$AGENT is not running" echo "Restarting service" systemctl start $AGENT sleep 5s if (( $(ps -ef | grep -v grep | grep $SERVICE | wc -l) > 0 )) then sleep 2s echo "$AGENT service is now running" fi fi

Filed Under: Cloud, Linux Tagged With: agent, bash, gce, restart

GCE Agent Powershell

May 11, 2020

This is a Powershell script to restart a service if it’s down.

$ServiceName = 'GCEAgent'
$arrService = Get-Service -Name $ServiceName
 
if ($arrService.Status -ne 'Running')
{
 
    Start-Service $ServiceName
    write-host $arrService.status
    write-host 'Service starting'
    Start-Sleep -seconds 60
    $arrService.Refresh()
    if ($arrService.Status -eq 'Running')
    {
        Write-Host 'GCE Agent Service is now Running'
    }
 
}
else
{
    Write-Host 'GCE Agent Service is Running'
}

$ServiceName = 'GCEAgent' $arrService = Get-Service -Name $ServiceName if ($arrService.Status -ne 'Running') { Start-Service $ServiceName write-host $arrService.status write-host 'Service starting' Start-Sleep -seconds 60 $arrService.Refresh() if ($arrService.Status -eq 'Running') { Write-Host 'GCE Agent Service is now Running' } } else { Write-Host 'GCE Agent Service is Running' }

Filed Under: Cloud, Windows Tagged With: check, powershell, restart, service

AWS EC2 Describe Snapshots

May 7, 2020

Here’s how to describe snapshots using query with tags.

aws ec2 describe-snapshots \
--owner-ids xxxxxxxxxxx \
--profile default \
--region us-east-2 \
--output text \
--query "Snapshots[*].[SnapshotId,Tags[?Key=='Name'].Value[] | [0]]"

aws ec2 describe-snapshots \ --owner-ids xxxxxxxxxxx \ --profile default \ --region us-east-2 \ --output text \ --query "Snapshots[*].[SnapshotId,Tags[?Key=='Name'].Value[] | [0]]"

Result.

snap-xxxxxxxxxxxxxxxxx	Server1
snap-xxxxxxxxxxxxxxxxx	Server2

snap-xxxxxxxxxxxxxxxxx Server1 snap-xxxxxxxxxxxxxxxxx Server2

Filed Under: Cloud Tagged With: aws, describe, ec2, output, snapshots, tags, text

PHP Modules

May 7, 2020

Here are some missing PHP modules on my WordPress install.

apt install php-gd php-dom php-mbstring php-imagick php-zip

apt install php-gd php-dom php-mbstring php-imagick php-zip

Reboot Apache after the install.

systemctl restart apache2

systemctl restart apache2

Filed Under: PHP, WP Tagged With: dom, gd, imagick, mbstring, modules, zip

Linux Screen

May 7, 2020

If you don’t have it installed.

yum install screen
apt install screen

yum install screen apt install screen

Before you run a process, run screen, and detach.

screen
# run the command
ping yahoo.com
# ctrl-a and ctrl-d to detach

screen # run the command ping yahoo.com # ctrl-a and ctrl-d to detach

To reattach, get a list of screen sessions, and attach to it.

screen -ls
# result is somewhat similar to below
4452.hostname
# attach to it
screen -dr 4452.hostname

screen -ls # result is somewhat similar to below 4452.hostname # attach to it screen -dr 4452.hostname

To stop, just type exit from the screen terminal.

Filed Under: Linux Tagged With: attach, detach, screen

  • Home
  • About
  • Archives

Copyright © 2023