bash variables

Here’s how to read Bash variables from another file. Contents of config.sh #!/bin/bash var1='thisisvariableone' var2='thisisvariabletwo' Call config.sh from another script. #!/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.

June 27, 2020 · 1 min · ulysses

internet test

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 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 So, I now have a record when it was up or down.

June 26, 2020 · 1 min · ulysses

largest files and directories

Here’s the command to find the largest files and directories in Linux. du -a /var | sort -n -r | head -n 20

June 24, 2020 · 1 min · ulysses

timedatectl

Here’s another way of setting your server’s timezone. See all the options under North America. timedatectl list-timezones | grep -i America Set timezone. timedatectl set-timezone America/New_York To check. date Restart cron if needed. systemctl restart cron.service

June 24, 2020 · 1 min · ulysses

gcp load balancer logging

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"

June 21, 2020 · 1 min · ulysses

ffmpeg offset audio

If your audio is out of sync, you can fix using ffmpeg. ffmpeg -i source.mp4 \ -i livestream.mp4 \ -map 0:0 -map 1:1 \ -acodec copy \ -vcodec copy \ -itsoffset 0.100 \ output.mp4 The ffmpeg fix is fast. A 1GB file took less than 30 seconds to run. Adjust -tsoffset until you find the sweet spot.

June 19, 2020 · 1 min · ulysses

ansible run updates

Here’s a simple adhoc to run updates on systems in Ansible. ansible servers -m apt -a "upgrade=yes update_cache=yes" -b Results: server | SUCCESS => { "changed": false, "msg": "Reading package lists... Building dependency tree... Reading state information... Calculating upgrade... 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.", "stderr": "", "stderr_lines": [], "stdout": "Reading package lists... Building dependency tree... Reading state information... Calculating upgrade... 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.", "stdout_lines": [ "Reading package lists...", "Building dependency tree...", "Reading state information...", "Calculating upgrade...", "0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." ] } If you want to reboot a remote server. ...

June 18, 2020 · 1 min · ulysses

wordpress posts revision

How to turn on post revisions in WordPress. Edit wp-config.php. /** WordPress Revisions */ define('WP_POST_REVISIONS', false); Change to: /** WordPress Revisions */ define('WP_POST_REVISIONS', 10); 10 is the number of revisions you want to keep.

June 18, 2020 · 1 min · ulysses

copy ssh key to server

Here’s the command to copy a secret key to a remote server. ssh-copy-id user@servername This assumes you already generated a key.

June 16, 2020 · 1 min · ulysses

linux useradd

Here’s the command to add a Linux user. useradd -m -s $(which bash) -G sudo ulysses -m creates a home directory. -s selects a shell. -G adds user to a sudo group.

June 16, 2020 · 1 min · ulysses