Using Wake on LAN With Google Wifi

Taking the time to write this one up for some other poor soul like me in the future who couldn’t find adequate answers.

Long story short – yes – “Wake on LAN” does work with Google Wifi.

Here are some steps:

  1. Know your IPv4 external address and/or bind it to a Dynamic DNS Service like No-Ip or DuckDNS
    • It is very common for an ISP to just flat give you a new IP address – you have to know this address and understand that if your IPv4 address changes you cannot do a damn thing about it other than mitigate ahead of time
    • We as residential customers have little to no guarantee on our parameters with bandwidth or otherwise – because we’re residential
  2. Have Wake on LAN up and working in a Local IPv4 context first
    • Aka connected to home wifi network – issue the “Magic Packet” – AT HOME
    • If you can’t get it working using your 192.168.* version of your IP while you’re sitting at home – you absolutely have to figure that out first – so stop reading and go figure that out before attempting an external context
  3. Set the following parameters on the Google Wifi Android or iPhone Application:
    • Google Wifi App -> Network & General -> Advanced Networking -> DHCP IP reservations -> Plus Button -> Choose Computer -> Leave Number Default -> Next -> Done
      • Change default if you want but unless you are truly looking for more debug and/or actually require a custom IP number – just leave it alone – no one cares about your fancy 3 digit number other than you – no one will see it – just leave it default
    • Google Wifi App -> Network & General -> Advanced Networking -> Port Management -> Plus Button -> Choose Computer – Use below settings and hit Done
      • Internal Port – 7
      • External Port – 1337
      • Remarks:
        • Internal Port – 7 is default what your computer will listen on locally and/or 9 – but 7 is what my computer responds on
        • External Port – Goal is to choose literally any number other than that is a valid port number – some notes I saw online suggested that our ISP’s have potentially gotten in the habit of straight up blocking these before they even reach the modem – so usage of a nonstandard port fixes this issue
  4. For your test case – I highly suggest starting with the physical numeric IPv4 address before attempting to use any Dynamic DNS solution – just so you know it works bare minumum and can rule out any other variables
  5. Connected to your Home Wifi – go google “what is my current ip address ipv4”
    • Write that down or screenshot it
  6. Disconnected from Home Wifi – Download a Wake on LAN application on your phone and do the below settings based off previous data in this guide
    • I used the app “Wake on LAN” on Android
    • IP/Hostname/Etc – input data from Step 5
    • Port – 1337 (or whatever you customized it to – remember my note around blockage and usage of nonstandard ports)
    • Send WOL packet – should work assuming you followed guidance on Step 2 – if you can’t get Wake On Lan working on your home network first you’re only wasting your own time by adding extra debug steps

Let me know in the comments down below your experience – despite Google Support stating that WOL isn’t supported in a few searches I saw – worked just fine for me.

Debugging what event woke a sleeping Windows Computer

I’m on a mission right now to keep my system OFF as much as possible after the recent failure of my GTX 980.

The Great GPU Shortage of 2020/2021 is no joke – I finally found a GTX 3070 and I intend to keep this card running for years to come. Hindsight though – 7 years from a electrical component is extremely impressive for a computer I used to leave on day in and out.

Shoutout to Henry in Atlanta for being an absolute wonderful human being and selling local AND not scalping – faith in humanity restored!

Right so back to the subject at hand – I’m working on implementing aggressive sleep policies for decreased system up time and overall lower temperatures to kill wear and tear.

I’ve migrated my computer to a cabinet in my living room so it’s absolutely critical that the computer stays off as much as possible in the event someone accidentally closes the cabinet door when it’s not in use.

The below command will show what woke your computer from its slumber last.

powercfg -lastwake

Imagine my surprise when I found out a Hard Drive Imaging/Backup Application that was installed years ago – EaseUs ToDo Backup – was the culprit.

As I continue this journey to peak sleep zen I’ll update this article further with my personal findings.

Recursive pkgdiff for WAR and JAR comparison in Java

This’ll be one of the most useful utilities I’ve written to date

Features:

  • Whitelisting of Desired JAR String Matches
  • Option to enable/disable whitelisting
  • pkgdiff over parent WARs and all children JAR files
  • Option to enable/disable decompiling
    • Decompiles all detected/whitelisted (if enabled) jar files and attaches source back to jar file
    • Used for delta analysis in html report that pkgdiff creates
  • Timestamped Reports – Both Zipped and Regular Folders
    • Each time script is ran clears current working report directory
    • At end of script takes output and copies to timestamped directory
    • At end of script zips the timestamped directory for portability

The idea is to do the following:

  1. Runs pkgdiff on the initial two WAR files
  2. Unzips the WAR files
  3. Searches for any JAR files in each unzipped path and indexes them
  4. Attempts to find a JAR match across both of the unzipped WAR paths
    • Strips version numbers from the jar filenames
    • Checks the whitelist to see if the JAR matches ones you desire to be processed
  5. (Optional) Runs JD Decompiler and attaches the decompiled code back to the JAR
  6. Runs pkgdiff on the matched jar files
  7. Repeat steps 4-6 on all jars
  8. Takes output and copies all to timestamped directory
  9. Zips timestamped directory for portability
    • Does not remove timestamped directory just zips it

Repo URLhttps://github.com/qwertycody/Recursive_PkgDiff_Java

Batch Script to SFTP Download a Log File, Filename Timestamp, and Remotely Tail Log at the end

Another morph of the previous days utility script – does the following:

  1. Download the Remote Log File using SFTP
  2. Copy downloaded file to a timestamped filename
  3. Tail the Downloaded Log file at the end
@echo off
 
REM ######################################################
REM #### BEGIN - Do Not Touch - Misc Setup Variables: ####
REM ######################################################
 
REM SCRIPT_DIRECTORY is defined as the directory that this script currently exists in
SET "SCRIPT_DIRECTORY=%~dp0"
SET "SCRIPT_DIRECTORY=%SCRIPT_DIRECTORY:~0,-1%"
 
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set VARIABLE_DATETIME=%%a
set VARIABLE_YEAR=%VARIABLE_DATETIME:~0,4%
set VARIABLE_MONTH=%VARIABLE_DATETIME:~4,2%
set VARIABLE_DAY=%VARIABLE_DATETIME:~6,2%
set VARIABLE_HOUR=%VARIABLE_DATETIME:~8,2%
set VARIABLE_MINUTE=%VARIABLE_DATETIME:~10,2%
set VARIABLE_SECOND=%VARIABLE_DATETIME:~12,2%
set VARIABLE_TIMESTAMP=%VARIABLE_YEAR%-%VARIABLE_MONTH%-%VARIABLE_DAY%
 
REM ####################################################
REM #### END - Do Not Touch - Misc Setup Variables: ####
REM ####################################################
 
REM #######################################################
REM ### BEGIN - Customized Remote/Local Setup Variables ###
REM #######################################################
 
REM PLINK and PSFTP Application Paths
SET "PLINK=C:/Program Files/Putty/plink.exe"
SET "PSFTP=C:/Program Files/Putty/psftp.exe"
 
REM Setup - Remote Linux Host, Username, and Potential Command to Run
SET "REMOTE_HOSTNAME=hostname.com"
SET "REMOTE_USERNAME=username"
 
REM Setup - Private Key for Authentication
SET "LOCAL_PRIVATE_KEY=%SCRIPT_DIRECTORY%\private_key.ppk"
 
REM Setup - Local File To Transfer - Local Filename Variables including Name, Path, and Timestamp
SET "LOCAL_FILENAME=filename.log"
SET "LOCAL_DIRECTORY=%SCRIPT_DIRECTORY%\"
SET "LOCAL_PATH=%LOCAL_DIRECTORY%\%LOCAL_FILENAME%"
SET "LOCAL_PATH_TIMESTAMPED=%LOCAL_DIRECTORY%\%VARIABLE_TIMESTAMP%_%LOCAL_FILENAME%"
 
REM Setup - Final Transfer Path to Remote Server - Remote Directory and Final Filename to Transmit
SET "REMOTE_FILENAME=filename.log"
SET "REMOTE_DIRECTORY=/remote/log/directory"
SET "REMOTE_PATH=%REMOTE_DIRECTORY%/%REMOTE_FILENAME%"
SET "REMOTE_PATH_TIMESTAMPED=%REMOTE_DIRECTORY%/%VARIABLE_TIMESTAMP%_%REMOTE_FILENAME%"

SET "MISC_COMMAND=tail -f -n+1 %REMOTE_DIRECTORY%/%REMOTE_FILENAME%"

REM #####################################################
REM ### END - Customized Remote/Local Setup Variables ###
REM #####################################################
 
REM #####################################################
REM ### BEGIN - Script Actions Using Setup Variables  ###
REM #####################################################
 
REM File Download and Staging - Remove Current Copies of Local File
del /f "%LOCAL_PATH%"
 
REM SFTP - Stage SFTP Commands in Temp Script
SET "TEMP_BATCH_FILE=%SCRIPT_DIRECTORY%\psftp.batch"   
echo cd %REMOTE_DIRECTORY% > "%TEMP_BATCH_FILE%"
echo get "%REMOTE_FILENAME%" >> "%TEMP_BATCH_FILE%"
 
REM SFTP - Execute Transfer
"%PSFTP%" -i "%LOCAL_PRIVATE_KEY%" ^
         -b "%TEMP_BATCH_FILE%" ^
         "%REMOTE_USERNAME%@%REMOTE_HOSTNAME%"
 
REM SFTP - Remove Temp Script
del /f "%TEMP_BATCH_FILE%"
 
REM Copy File to Timestamp Name 
copy /B /Y "%LOCAL_PATH%" "%LOCAL_PATH_TIMESTAMPED%"
 
REM Issue Command - Tail Live Log
"%PLINK%" -i "%LOCAL_PRIVATE_KEY%" ^
            "%REMOTE_USERNAME%@%REMOTE_HOSTNAME%" ^
            "%MISC_COMMAND%"

REM ###################################################
REM ### END - Script Actions Using Setup Variables  ###
REM ###################################################

pause

Batch Script to SFTP Download an Entire Directory and Timestamp it Locally

This same script I’ve originally written a few days ago is morphing again for another purpose and does the following.

  1. Create a Logs Directory Locally and a Timestamped Sub Directory
  2. SFTP an entire remote directory tree to this Local Directory
@echo off 

REM ###################################################### 
REM #### BEGIN - Do Not Touch - Misc Setup Variables: #### 
REM ###################################################### 

REM SCRIPT_DIRECTORY is defined as the directory that this script currently exists in 
SET "SCRIPT_DIRECTORY=%~dp0" 
SET "SCRIPT_DIRECTORY=%SCRIPT_DIRECTORY:~0,-1%" 

for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set VARIABLE_DATETIME=%%a 
set VARIABLE_YEAR=%VARIABLE_DATETIME:~0,4% 
set VARIABLE_MONTH=%VARIABLE_DATETIME:~4,2% 
set VARIABLE_DAY=%VARIABLE_DATETIME:~6,2% 
set VARIABLE_HOUR=%VARIABLE_DATETIME:~8,2% 
set VARIABLE_MINUTE=%VARIABLE_DATETIME:~10,2% 
set VARIABLE_SECOND=%VARIABLE_DATETIME:~12,2% 
set VARIABLE_TIMESTAMP=%VARIABLE_YEAR%-%VARIABLE_MONTH%-%VARIABLE_DAY% 

REM #################################################### 
REM #### END - Do Not Touch - Misc Setup Variables: #### 
REM #################################################### 

REM ####################################################### 
REM ### BEGIN - Customized Remote/Local Setup Variables ### 
REM ####################################################### 

REM PLINK and PSFTP Application Paths 
SET "PLINK=C:/Program Files/Putty/plink.exe" 
SET "PSFTP=C:/Program Files/Putty/psftp.exe" 

REM Setup - Remote Linux Host, Username, and Potential Command to Run 
SET "REMOTE_HOSTNAME=hostname.com" 
SET "REMOTE_USERNAME=username" 

REM Setup - Private Key for Authentication 
SET "LOCAL_PRIVATE_KEY=%SCRIPT_DIRECTORY%\private_key.ppk" 

REM Setup - Local File To Transfer - Local Filename Variables including Name, Path, and Timestamp 
SET "LOCAL_DIRECTORY=%SCRIPT_DIRECTORY%\Logs" 
SET "LOCAL_DIRECTORY_TIMESTAMPED=%LOCAL_DIRECTORY%\%VARIABLE_TIMESTAMP%" 

REM Setup - Final Transfer Path to Remote Server - Remote Directory and Final Filename to Transmit 
SET "REMOTE_DIRECTORY=/remote/path/to/logs" 
 
REM ##################################################### 
REM ### END - Customized Remote/Local Setup Variables ### 
REM ##################################################### 

REM ##################################################### 
REM ### BEGIN - Script Actions Using Setup Variables  ### 
REM ##################################################### 

mkdir "%LOCAL_DIRECTORY%" 
mkdir "%LOCAL_DIRECTORY_TIMESTAMPED%" 

REM Change to Timestamp Directory 
cd /d "%LOCAL_DIRECTORY_TIMESTAMPED%" 

REM SFTP - Stage SFTP Commands in Temp Script 
SET "TEMP_BATCH_FILE=%SCRIPT_DIRECTORY%\psftp.batch"    
echo cd %REMOTE_DIRECTORY% > "%TEMP_BATCH_FILE%" 
echo get -r %REMOTE_DIRECTORY% >> "%TEMP_BATCH_FILE%" 

REM SFTP - Execute Transfer 
"%PSFTP%" -i "%LOCAL_PRIVATE_KEY%" ^ 
         -b "%TEMP_BATCH_FILE%" ^ 
         "%REMOTE_USERNAME%@%REMOTE_HOSTNAME%" 

REM SFTP - Remove Temp Script 
del /f "%TEMP_BATCH_FILE%" 

REM ################################################### 
REM ### END - Script Actions Using Setup Variables  ### 
REM ################################################### 

pause 

Batch Script to Browser Download, Filename Timestamp, SFTP Upload, and Execute Remote SSH Command

If you follow my blog you might have seen a similar blog post the other day where I wrote a script to automatically execute an SSH command and SFTP download a file – using Putty Utilities.

https://garrett.dev/2020/12/09/automatic-script-for-ssh-command-and-sftp-download-in-git-bash/

Now I have retooled that same exact script, except this time it is written in Windows Batch Script format.

The script does the following:

  1. Opens a hard-coded URL in the default web browser and waits for user to press key to continue
    • Practical use case would be downloading a file from OneDrive or any service that doesn’t support direct URL download via curl or wget
  2. Moves the file to the predefined script directory – copies it to a timestamped name of YYYY-MM-DD_filename.extension
  3. Uploads the file using SFTP to the remote server
  4. Issues an SSH Command to copy the remote file to a timestamped name like in previosu step
  5. Issues an SSH Command of your choosing

Overall – this is going to save me loads of time personally with a few tedious tasks and was fun writing it.

@echo off

REM ######################################################
REM #### BEGIN - Do Not Touch - Misc Setup Variables: ####
REM ######################################################

REM SCRIPT_DIRECTORY is defined as the directory that this script currently exists in
SET "SCRIPT_DIRECTORY=%~dp0"
SET "SCRIPT_DIRECTORY=%SCRIPT_DIRECTORY:~0,-1%"

for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set VARIABLE_DATETIME=%%a
set VARIABLE_YEAR=%VARIABLE_DATETIME:~0,4%
set VARIABLE_MONTH=%VARIABLE_DATETIME:~4,2%
set VARIABLE_DAY=%VARIABLE_DATETIME:~6,2%
set VARIABLE_HOUR=%VARIABLE_DATETIME:~8,2%
set VARIABLE_MINUTE=%VARIABLE_DATETIME:~10,2%
set VARIABLE_SECOND=%VARIABLE_DATETIME:~12,2%
set VARIABLE_TIMESTAMP=%VARIABLE_YEAR%-%VARIABLE_MONTH%-%VARIABLE_DAY%

REM ####################################################
REM #### END - Do Not Touch - Misc Setup Variables: ####
REM ####################################################

REM #######################################################
REM ### BEGIN - Customized Remote/Local Setup Variables ###
REM #######################################################

REM PLINK and PSFTP Application Paths
SET "PLINK=c:/Program Files/PuTTY/plink.exe"
SET "PSFTP=c:/Program Files/PuTTY/psftp.exe"

REM Setup - Remote Linux Host, Username, and Potential Command to Run
SET "REMOTE_HOSTNAME=hostname.com"
SET "REMOTE_USERNAME=username"
SET "REMOTE_COMMAND=bash -c 'cd /myCoolDirectory/subDirectory && ls -al'"

REM Setup - Private Key for Authentication
SET "LOCAL_PRIVATE_KEY=%SCRIPT_DIRECTORY%\private_key.ppk"

REM Setup - Local File To Transfer - Local Filename Variables including Name, Path, and Timestamp
SET "LOCAL_FILENAME=filename.extension"
SET "LOCAL_DIRECTORY=%SCRIPT_DIRECTORY%\"
SET "LOCAL_PATH=%LOCAL_DIRECTORY%\%LOCAL_FILENAME%"
SET "LOCAL_PATH_TIMESTAMPED=%LOCAL_DIRECTORY%\%VARIABLE_TIMESTAMP%_%LOCAL_FILENAME%"

REM Setup - Final Transfer Path to Remote Server - Remote Directory and Final Filename to Transmit
SET "REMOTE_FILENAME=filename.extension"
SET "REMOTE_DIRECTORY=/myCoolDirectory/subDirectory"
SET "REMOTE_PATH=%REMOTE_DIRECTORY%/%REMOTE_FILENAME%"
SET "REMOTE_PATH_TIMESTAMPED=%REMOTE_DIRECTORY%/%VARIABLE_TIMESTAMP%_%REMOTE_FILENAME%"

REM Setup - Default Download Name from Web Browser - Local Filename That Gets Downloaded From Web Browser
SET "DOWNLOAD_DIRECTORY=%USERPROFILE%\Downloads"
SET "DOWNLOAD_FILENAME=filename.extension"
SET "DOWNLOAD_PATH=%DOWNLOAD_DIRECTORY%\%DOWNLOAD_FILENAME%"

REM #####################################################
REM ### END - Customized Remote/Local Setup Variables ###
REM #####################################################

REM #####################################################
REM ### BEGIN - Script Actions Using Setup Variables  ###
REM #####################################################

REM File Download and Staging - Remove Current Copies of Local File
del /f "%DOWNLOAD_PATH%"
del /f "%LOCAL_PATH%"

REM File Download and Staging - Open URL in Chrome for Download
REM
REM If URL contains % paste in Notepad++ - find replace % with %% to properly escape
REM
SET "URL_TO_OPEN=https://sharepoint.com/filename.extension%%tokenThing%%ect"
start "" "%URL_TO_OPEN%"
echo "Press any key when file is finished downloading..."
pause

REM File Download and Staging - Move Downloaded File to Script Directory
move /y "%DOWNLOAD_PATH%" "%LOCAL_PATH%"
copy /B /Y "%LOCAL_PATH%" "%LOCAL_PATH_TIMESTAMPED%"

REM SFTP - Stage SFTP Commands in Temp Script
SET "TEMP_BATCH_FILE=%SCRIPT_DIRECTORY%\psftp.batch" 	
echo cd %REMOTE_DIRECTORY% > "%TEMP_BATCH_FILE%"
echo put "%LOCAL_FILENAME%" >> "%TEMP_BATCH_FILE%"

REM SFTP - Execute Transfer
"%PSFTP%" -i "%LOCAL_PRIVATE_KEY%" ^
		 -b "%TEMP_BATCH_FILE%" ^
		 "%REMOTE_USERNAME%@%REMOTE_HOSTNAME%" 

REM SFTP - Remove Temp Script
del /f "%TEMP_BATCH_FILE%"

REM Issue Command - Remote Copy of Transferred File to Timestamp File
SET "REMOTE_TIMESTAMP_COMMAND=cp '%REMOTE_PATH%' '%REMOTE_PATH_TIMESTAMPED%'"
"%PLINK%" -i "%LOCAL_PRIVATE_KEY%" ^
			"%REMOTE_USERNAME%@%REMOTE_HOSTNAME%" ^
			"%REMOTE_TIMESTAMP_COMMAND%"

REM Issue Command - Execute Misc Command
"%PLINK%" -i "%LOCAL_PRIVATE_KEY%" ^
			"%REMOTE_USERNAME%@%REMOTE_HOSTNAME%" ^
			"%REMOTE_COMMAND%"

REM ###################################################
REM ### END - Script Actions Using Setup Variables  ###
REM ###################################################

Automatic Script for SSH Command and SFTP Download In Git Bash

Here’s a script I wrote today to automatically execute a command over SSH using Putty’s PLINK and subsequently download a file using Putty’s PSFTP from a remote Linux host.

My exact use case is using this to execute a remote command that pulls a file from a Docker container to a temp directory. Then I download that file to my local Windows computer.

This pairs well with another blog post I wrote that allows you to automatically set up a public/private key pair and simply copy paste to a notepad located at the below link.

https://garrett.dev/2019/06/13/bash-script-for-automatic-creation-and-generation-of-public-private-key-for-linux-server-login/

Automate everything – that’s my philosophy.

#Ensure nothing happens outside the directory this script is ran from
cd "$(dirname "$0")"
SCRIPT_DIRECTORY=$(pwd)

REMOTE_HOSTNAME="hostname.com"
REMOTE_USERNAME="username"

REMOTE_COMMAND="bash -c 'cd /remoteDirectory/subDirectory/ && sh getFromDockerContainer.sh'"

#Double slash is for git bash path conversion compatibility
REMOTE_FILENAME="//remoteDirectory/subDirectory/file.extension"
LOCAL_FILENAME="$SCRIPT_DIRECTORY/file.extension"

LOCAL_PRIVATE_KEY="$SCRIPT_DIRECTORY/private_key.ppk"

PLINK="/c/Program Files/PuTTY/plink.exe"
PSFTP="/c/Program Files/PuTTY/psftp.exe"

rm -f "$LOCAL_FILENAME"

"$PLINK" -i "$LOCAL_PRIVATE_KEY" "$REMOTE_USERNAME@$REMOTE_HOSTNAME" "$REMOTE_COMMAND"

TEMP_BATCH_FILE="$SCRIPT_DIRECTORY/psftp.batch"

echo "get $REMOTE_FILENAME" > "$TEMP_BATCH_FILE"

"$PSFTP" -i "$LOCAL_PRIVATE_KEY" -b "$TEMP_BATCH_FILE" "$REMOTE_USERNAME@$REMOTE_HOSTNAME"

rm -f "$TEMP_BATCH_FILE"

Yahoo is Removing Free Auto-Forwarding – Here’s a Detailed POP3 Workaround

If you grew up naïve like me chances are you had a Yahoo email account at one time or another.

Times have changed – better options surfaced – maybe you decided to auto-forward all Yahoo mail to your Gmail address.

Well apparently this is going behind a paywall on 01/01/2021 – see below email screenshot.

The good news is – apparently they aren’t removing POP3 functionality and putting that behind a paywall.

So here is a sequence of steps to ensure your legacy email is still pumping into Gmail – if you have a few straggler accounts or newsletters that haven’t been properly changed over yet.

  1. Optional – probably do a security checkup on this account and ensure it has a strong password with a email backup in case Yahoo inevitably gets hacked again
  2. Disable Auto Forwarding in your Yahoo
  3. Generate an App Password for usage in Gmail POP3 settings
  4. Open this page for reference of Yahoo POP3 settings
  5. Plug your username and the aforementioned App Password in from Step 3

Batch – One Way Directory Sync

Have had a need to write this script for a while and finally took the time to do it today.

As a rule of thumb, I have an extreme distrust of the Windows file copy/paste functionality when it comes to deep directory structures.

It only gets worse when you add in network shares, so cue the paranoia.

Below is a script that has two examples:

  • Copy a single file from a remote directory to a local directory using robocopy
  • Copy an entire directory structure from remote to a local directory using robocopy

Both of these examples will only copy the delta between the two, so if the remote is newer or has a different file size the local representation will be purged of the differences and sync only the differences. In addition, it will log the entire transaction to a separate timestamped log file each time it is ran so we can analyze if there were transmission/permission errors.

This is helpful because network shares are prone to failure, especially over a VPN.

@echo off

REM #####################################################
REM #### Generate Timestamp String for Log Filename: ####
REM #####################################################

for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set VARIABLE_DATETIME=%%a
set VARIABLE_YEAR=%VARIABLE_DATETIME:~0,4%
set VARIABLE_MONTH=%VARIABLE_DATETIME:~4,2%
set VARIABLE_DAY=%VARIABLE_DATETIME:~6,2%
set VARIABLE_HOUR=%VARIABLE_DATETIME:~8,2%
set VARIABLE_MINUTE=%VARIABLE_DATETIME:~10,2%
set VARIABLE_SECOND=%VARIABLE_DATETIME:~12,2%
set VARIABLE_TIMESTAMP=%VARIABLE_YEAR%-%VARIABLE_MONTH%-%VARIABLE_DAY%_%VARIABLE_HOUR%-%VARIABLE_MINUTE%-%VARIABLE_SECOND%

REM ##############################################################
REM #### Parameters used in this script for robocopy command: ####
REM ##############################################################
REM
REM e - Copies subdirectories. This option automatically includes empty directories.
REM
REM z - Copies files in restartable mode.
REM
REM purge - Deletes destination files and directories that no longer exist in the source. Using this option with the /e option and a destination directory, allows the destination directory security settings to not be overwritten.
REM 
REM log+ - Writes the status output to the log file (appends the output to the existing log file).
REM 
REM tee - Writes to console window and log file at the same time instead of just the log file when using the log option

REM SCRIPT_DIRECTORY is defined as the directory that this script currently exists in
SET "SCRIPT_DIRECTORY=%~dp0"
SET "SCRIPT_DIRECTORY=%SCRIPT_DIRECTORY:~0,-1%"

echo "Working Directory = %SCRIPT_DIRECTORY%"

SET "VARIABLE_RETRY_WAIT=1"
echo "Wait Time for Retry = %VARIABLE_RETRY_WAIT%"

SET "VARIABLE_RETRY_COUNT=1000"
echo "Retry Count Before Giving Up = %VARIABLE_RETRY_COUNT%"

SET "VARIABLE_LOG=%SCRIPT_DIRECTORY%\sync_%VARIABLE_TIMESTAMP%.log"
echo "Log File = %VARIABLE_LOG%"

REM ############################################################
REM #### FILE - Getting specific_file_that_i_want.extension ####
REM ############################################################

SET "VARIABLE_LOCAL_DIR=%SCRIPT_DIRECTORY%\network-share-directory"
echo "Local Directory = %VARIABLE_LOCAL_DIR%"

SET "VARIABLE_REMOTE_DIR=\\remote-file-share\path\to\directory\to\sync\network-share-directory"
echo "Remote Directory = %VARIABLE_REMOTE_DIR%"

REM Example of copying a single file with robocopy
robocopy /e /Z /purge /W:%VARIABLE_RETRY_WAIT% ^
                      /r:%VARIABLE_RETRY_COUNT% ^
                      /tee ^
                      "/log+:%VARIABLE_LOG%" ^
                      "%VARIABLE_REMOTE_DIR%" ^
                      "%VARIABLE_LOCAL_DIR%" ^
                      "specific_file_that_i_want.extension"

REM #####################################################
REM #### DIRECTORY - Getting network-share-directory ####
REM #####################################################

SET "VARIABLE_LOCAL_DIR=%SCRIPT_DIRECTORY%\network-share-directory"
echo "Local Directory = %VARIABLE_LOCAL_DIR%"

SET "VARIABLE_REMOTE_DIR=\\remote-file-share\path\to\directory\to\sync\network-share-directory"
echo "Remote Directory = %VARIABLE_REMOTE_DIR%"

REM Example of copying a single file with robocopy
robocopy /e /Z /purge /W:%VARIABLE_RETRY_WAIT% ^
                      /r:%VARIABLE_RETRY_COUNT% ^
                      /tee ^
                      "/log+:%VARIABLE_LOG%" ^
                      "%VARIABLE_REMOTE_DIR%" ^
                      "%VARIABLE_LOCAL_DIR%"

pause					  

Docker – Bulk Stop and Remove Containers in Bash

Had a bunch of annoying no-name containers I needed to remove because forgot to add the “–rm” flag on my “docker run” commands used for debugging containers.

Below is a snippet that works in git-bash and normal linux bash environments for bulk deletion of containers based on their name matching the grep pipe.

#This pattern targets and removes the weirdly named ones docker generates if no name is provided
#
#Test it first to ensure it targets the right containers!! - first command will echo all the ones that will be removed
docker ps -a | grep -v ":" | grep "_" | awk '{print $1}' | xargs echo
docker ps -a | grep -v ":" | grep "_" | awk '{print $1}' | xargs docker stop
docker ps -a | grep -v ":" | grep "_" | awk '{print $1}' | xargs docker rm -v

#This pattern targets and removes the ones I personally created in bulk that had "test_" in the name
docker ps -a | grep "test_" | awk '{print $1}' | xargs docker stop
docker ps -a | grep "test_" | awk '{print $1}' | xargs docker rm -v