• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

Archives for June 2020

Linux Script

June 30, 2020

The script command records all your keystrokes and output into a file called typescript.

You can start recording by simply typing script.

script
Script started, file is typescript
df -h
ls -l
exit

script Script started, file is typescript df -h ls -l exit

Typing exit stops the recording. Just cat typescript to see your recording.

cat typescript

cat typescript

Filed Under: Linux Tagged With: keystrokes, output, record, script, typescript

PHP 7.0 to 7.4 Upgrade

June 28, 2020

Here are steps I took to upgrade from PHP 7.0 to 7.4 on Ubuntu 18.04 LTS.

Login as root, otherwise use sudo for all commands.

# use 3rd party ppa repo
add-apt-repository ppa:ondrej/php
apt -y update
apt -y upgrade
# install php-core
apt install php7.4 php7.4-common php7.4-cli
# add all the php extenstions your app needs
apt install php7.4-curl php7.4-json php7.4-gd php7.4-mbstring
apt install php7.4-intl php7.4-bcmath php7.4-bz2 php7.4-xml
apt install php7.4-readline php7.4-zip php7.4-mysql
# I'm using apache prefork MPM, so install it
apt install libapache2-mod-php7.4
a2enmod php7.4
# check version. Success!
php -v
# for good measure, reboot apache
systemctl restart apache2.service
# Finally, purge the old PHP versions
apt purge php7.0 libapache2-mod-php7.0

# use 3rd party ppa repo add-apt-repository ppa:ondrej/php apt -y update apt -y upgrade # install php-core apt install php7.4 php7.4-common php7.4-cli # add all the php extenstions your app needs apt install php7.4-curl php7.4-json php7.4-gd php7.4-mbstring apt install php7.4-intl php7.4-bcmath php7.4-bz2 php7.4-xml apt install php7.4-readline php7.4-zip php7.4-mysql # I'm using apache prefork MPM, so install it apt install libapache2-mod-php7.4 a2enmod php7.4 # check version. Success! php -v # for good measure, reboot apache systemctl restart apache2.service # Finally, purge the old PHP versions apt purge php7.0 libapache2-mod-php7.0

Finally, run update on more time to get all the latest updates.

apt -y update
apt -y upgrade
apt -y autoremove
apt-get --with-new-pkgs upgrade

apt -y update apt -y upgrade apt -y autoremove apt-get --with-new-pkgs upgrade

Filed Under: Linux Tagged With: 7.0, 7.4, php, ubuntu, upgrade

AWS CLI V2

June 28, 2020

How to install AWS CLI version 2.

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" unzip awscliv2.zip sudo ./aws/install

Filed Under: Cloud, Linux Tagged With: aws, cli, install, v2

Bash Variables

June 27, 2020

Here’s how to read Bash variables from another file.

Contents of config.sh

#!/bin/bash
var1='thisisvariableone'
var2='thisisvariabletwo'

#!/bin/bash var1='thisisvariableone' var2='thisisvariabletwo'

Call config.sh from another script.

#!/bin/bash
source config.sh
echo var1
echo var2

#!/bin/bash source config.sh echo var1 echo var2

This is extremely helpful if you have multiple scripts using a common variable. You just to update one file instead of multiple files. All the other scripts will read and pick up the same variables from a config file. You can use this to setup your global variables.

Filed Under: Linux Tagged With: another, bash, file, source, variable

Internet Test

June 26, 2020

My internet has been flaky lately. I wrote a script that logs my internet connection.

I’m running it in cron every minute.

#!/bin/bash
log='/home/ulysses/Code/spectrum.log'
if nc -zw1 google.com 443;
then 
  echo 'Spectrum is up' $(date) >> $log
else 
  echo 'Spectrum is down' $(date) >> $log
fi

#!/bin/bash log='/home/ulysses/Code/spectrum.log' if nc -zw1 google.com 443; then echo 'Spectrum is up' $(date) >> $log else echo 'Spectrum is down' $(date) >> $log fi

To view, just cat the log.

cat spectrum.log 
Spectrum is up Fri Jun 26 15:14:01 EDT 2020
Spectrum is up Fri Jun 26 15:15:01 EDT 2020
Spectrum is up Fri Jun 26 15:16:01 EDT 2020
Spectrum is up Fri Jun 26 15:17:01 EDT 2020
Spectrum is up Fri Jun 26 15:18:01 EDT 2020

cat spectrum.log Spectrum is up Fri Jun 26 15:14:01 EDT 2020 Spectrum is up Fri Jun 26 15:15:01 EDT 2020 Spectrum is up Fri Jun 26 15:16:01 EDT 2020 Spectrum is up Fri Jun 26 15:17:01 EDT 2020 Spectrum is up Fri Jun 26 15:18:01 EDT 2020

So, I now have a record when it was up or down.

Filed Under: Linux Tagged With: connection, internet, log, spectrum

Timedatectl

June 24, 2020

Here’s another way of setting your server’s timezone. See all the options under North America.

timedatectl list-timezones | grep -i America

timedatectl list-timezones | grep -i America

Set timezone.

timedatectl set-timezone America/New_York

timedatectl set-timezone America/New_York

To check.

date

date

Restart cron if needed.

systemctl restart cron.service

systemctl restart cron.service

Filed Under: Linux Tagged With: set, timedatectl, timezone

Largest Files and Directories

June 24, 2020

Here’s the command to find the largest files and directories in Linux.

du -a /var | sort -n -r | head -n 20

du -a /var | sort -n -r | head -n 20

Filed Under: Linux

GCP Load Balancer Logging

June 21, 2020

Go to Logging > Logs Viewer to monitor a GCP Load Balancer.

resource.type="http_load_balancer" AND resource.labels.url_map_name="your-lb" AND resource.labels.project_id="your-project-id"

resource.type="http_load_balancer" AND resource.labels.url_map_name="your-lb" AND resource.labels.project_id="your-project-id"

Filed Under: Cloud Tagged With: balancer, gcp, google, load, logging

  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to Next Page »
  • Home
  • About
  • Archives

Copyright © 2023