• Skip to main content

Uly.me

cloud engineer

  • Home
  • Archives
  • Search

conversion

Calculate Date to Epoch Time

June 24, 2022 by Ulysses

Here’s a script to convert date to epoch time on Mac OS.

#!/bin/bash
if [[ -z $1 ]]; then
  echo "Format: date2epoch.sh 2022/01/01-04:58:06"
else
  echo "$1"; date -j -f date -j -f "%Y/%m/%d-%T" "$1" +"%s"
fi

#!/bin/bash if [[ -z $1 ]]; then echo "Format: date2epoch.sh 2022/01/01-04:58:06" else echo "$1"; date -j -f date -j -f "%Y/%m/%d-%T" "$1" +"%s" fi

Result

$ ./date2epoch.sh 2022/08/31-22:00:00
2022/08/31-22:00:00
1661997600

$ ./date2epoch.sh 2022/08/31-22:00:00 2022/08/31-22:00:00 1661997600

Filed Under: Linux Tagged With: conversion, date, epoch

GB vs GiB

July 15, 2020 by Ulysses

Interesting facts between GB and GiB.

  • GB uses base 1000. GiB uses base 1024.
  • 1GB is 1,000,000,000 bytes. 1GiB is 1,073,741,824 bytes.
  • A 1TB drive is 1,000 GB. Or 931 GiB.
  • A 1TiB drive is 1000 GiB. Or 1099 GB.
  • To convert GB to GiB, multiply by (1000 / 1024).
  • To convert GiB to GB, divide by (1000 / 1024).

Filed Under: Linux Tagged With: 1000, 1024, conversion, gb, gib

PFX to PEM

April 22, 2020 by Ulysses

Here’s how to convert SSL certificate from PFX to PEM format.

#!/bin/bash
 
echo "This script converts SSL certificates from PFX to PEM."
read -p 'Enter PFX Certificate Name  : ' cert_pfx
read -p 'Enter the Import Passphrase : ' import_passphrase
 
openssl pkcs12 -in $cert_pfx -nocerts -out cert-key.pem -passin pass:$import_passphrase -passout pass:$import_passphrase
openssl pkcs12 -in $cert_pfx -clcerts -nokeys -out cert-body.pem -passin pass:$import_passphrase -passout pass:$import_passphrase
openssl pkcs12 -in $cert_pfx -nodes -nokeys -out cert-chain.pem -passin pass:$import_passphrase -passout pass:$import_passphrase
sleep 3
openssl rsa -in key.pem -out cert-private.key -passin pass:$import_passphrase -passout pass:$import_passphrase

#!/bin/bash echo "This script converts SSL certificates from PFX to PEM." read -p 'Enter PFX Certificate Name : ' cert_pfx read -p 'Enter the Import Passphrase : ' import_passphrase openssl pkcs12 -in $cert_pfx -nocerts -out cert-key.pem -passin pass:$import_passphrase -passout pass:$import_passphrase openssl pkcs12 -in $cert_pfx -clcerts -nokeys -out cert-body.pem -passin pass:$import_passphrase -passout pass:$import_passphrase openssl pkcs12 -in $cert_pfx -nodes -nokeys -out cert-chain.pem -passin pass:$import_passphrase -passout pass:$import_passphrase sleep 3 openssl rsa -in key.pem -out cert-private.key -passin pass:$import_passphrase -passout pass:$import_passphrase

This was covered in an earlier post, but this script prompts you for the passphrase.

Here’s the expected output.

  • cert-key.pem
  • cert-body.pem
  • cert-chain.pem
  • cert-private.key

Filed Under: Linux Tagged With: conversion, convert, openssl, pem, pfx

Bash Convert Bytes

January 26, 2020 by Ulysses

Here’s a function to convert bytes into kilo, mega, giga, tera up to zeta bytes.

function convert_bytes {
    bytes=$credits
    b=${bytes:-0}; d=''; s=0; S=(Bytes {K,M,G,T,E,P,Y,Z}B)
    while ((b > 1024)); do
        d="$(printf ".%02d" $((b % 1000 * 100 / 1000)))"
        b=$((b / 1000))
        let s++
    done
    echo "$b$d ${S[$s]}"
}
credits=2308974418330
echo $credits 
convert_bytes $credits

function convert_bytes { bytes=$credits b=${bytes:-0}; d=''; s=0; S=(Bytes {K,M,G,T,E,P,Y,Z}B) while ((b > 1024)); do d="$(printf ".%02d" $((b % 1000 * 100 / 1000)))" b=$((b / 1000)) let s++ done echo "$b$d ${S[$s]}" } credits=2308974418330 echo $credits convert_bytes $credits

Result is:

2308974418330
2.30 TB

2308974418330 2.30 TB

Filed Under: Linux Tagged With: bash, bytes, conversion, convert, function

Convert MP3 to OGG

July 4, 2019 by Ulysses

Convert MP3 to Vorbis OGG format using ffmpeg.

ffmpeg -i input.mp3 -c:a libvorbis -q:a 4 output.ogg

ffmpeg -i input.mp3 -c:a libvorbis -q:a 4 output.ogg

If you want multiple files, use a loop.

for f in ./*.mp3; do ffmpeg -i "$f" -c:a libvorbis -q:a 4 "${f/%mp3/ogg}"; done

for f in ./*.mp3; do ffmpeg -i "$f" -c:a libvorbis -q:a 4 "${f/%mp3/ogg}"; done

Filed Under: Misc Tagged With: conversion, ffmpeg, mp3, ogg, vorbis

  • Home
  • About
  • Contact

Copyright © 2022