SSH Port Forwarding Utility Script for Secured Endpoint Testing

Wrote this quick little diddy for testing endpoints with SOAP UI that are traditionally not reachable unless on a specific box that has an IP range or network that is whitelisted for connection.

Read comments below and change as needed for your respective endpoint.

Be sure to terminate the script afterwards so that the tunnel is closed.

#Change IP to AWS Server IP and Correct Username
AWS_SERVER_IP="192.168.1.1"
AWS_SERVER_PORT="22"
AWS_SERVER_USER="myCoolUser"

#External app address that can only be hit from the EC2 Instance or Server.
#This is useful for debugging of Web Service Endpoints and Connectivity Tests.

EXTERNAL_APP_IP="appHostnameThatCanOnlyBeHitFromAwsBox.com"
EXTERNAL_APP_PORT="443"

#Local Port that you will hit to test appHostnameThatCanOnlyBeHitFromAwsBox
#aka open Web Browser and go to https://localhost:1337 and this will forward 
#the connection to appHostnameThatCanOnlyBeHitFromAwsBox and the respective port

LOCAL_APP_PORT="1337"

#Set the proper unix style path using either Cygdrive or Git-Bash

PLINK_PATH="/c/path/PLINK.exe"
PPK_PATH="/c/path/pathToPpk.ppk"

#PLINK Syntax: 
#Password: -pw password 
#Private Key: -i "$PPK_PATH"
#Run in Background: & at the end

"$PLINK_PATH" -N -L $LOCAL_APP_PORT:$EXTERNAL_APP_IP:$EXTERNAL_APP_PORT -ssh $AWS_SERVER_USER@$AWS_SERVER_IP -P $AWS_SERVER_PORT -i "$PPK_PATH" 

Sendmail Example Usage for Bash

Useful snippet I wrote up after searching the internet for details on syntax for sendmail in Linux.

PRETTY_HOSTNAME=$(hostnamectl --pretty)
ADMIN_USERNAME='username'
ADMIN_PASSWORD='password'

sendmail -F "noreply@website.com" -it <<END_MESSAGE
Content-Type: text/html
MIME-Version: 1.0
To: person@email.com
Subject: [INFO] Connection Details
Hostname: $PRETTY_HOSTNAME <br />
If your program is down, do the following.
<br />
1. Open Putty <br />
2. Establish Connection to $PRETTY_HOSTNAME <br />
2a. Username: $ADMIN_USERNAME <br />
2b. Password: $ADMIN_PASSWORD <br />
3a. Check for the status of your program. <br />
If there are any questions or concerns please reach out to your server admin.
<br />
Thanks, <br />
Automated System 
END_MESSAGE

Bash Snippet to Dynamically Find Free Ports

Useful snippet I wrote for Docker container creation and dynamic port assignment.

ALLOCATED_PORT_LIST=()

function getFreePort()
{
	CHECK="do while"

	while [[ ! -z $CHECK ]]; do
		PORT=$(( ( RANDOM % 60000 )  + 1025 ))
		CHECK=$(sudo netstat -ap | grep $PORT)
	done

	echo $PORT
}

function getFreePort_Unallocated()
{
	PORT=$(getFreePort)
	
	MATCH_FOUND="false"

	for ALLOCATED_PORT in "${ALLOCATED_PORT_LIST[@]}"
	do
		if [ $PORT == $ALLOCATED_PORT ]; then
			MATCH_FOUND="true"
		fi
	done
	
	if [ $MATCH_FOUND == "true" ]; then
		getFreePort_Unallocated
	else
        ALLOCATED_PORT_LIST+=("$PORT")
		echo $PORT
	fi
}

PORT1=$(getFreePort_Unallocated)
PORT2=$(getFreePort_Unallocated)
PORT3=$(getFreePort_Unallocated)

WebLogic 12c – Changes to Domain Configuration Lost on Server Reboot

Had this weird issue where every time I’d made elaborate deployments and configuration changes in WebLogic Console, they’d miraculously disappear on server reboot.

Naturally, this is extremely infuriating considering the time it takes to deploy/configure just about ANYTHING in WebLogic.

So basically, I did some snooping around in the file structure after just about going insane and found this little diddy in the domain structure of the root.

/home/oracle/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/servers/domain_bak/config_prev/config.xml

I had read on this guys blog that he had a similar issue essentially:

Somehow, every time I applied changes even after deleting this pesky file the folder and backup file kept getting created and reverting ALL the changes on reboot and successful activation.

I got fed up.

As a provisional/permanent fix, I added a small line before invoking the startWebLogic.sh which is below.

rm -Rf /home/oracle/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/servers/domain_bak/*

Fixed my issue and worked like a charm.

Script for Debugging Windows Updates

Here’s a quick script I wrote to debug issues with Windows Update if you ever need to pass information along to IT.

To be run in git-bash and in it’s own folder.

###########################################
#### Declare Output Directory Settings ####
###########################################

OUTPUT_PATH="."
FOLDER_NAME=$(date +"%Y-%m-%d_%H-%M-%S")
FOLDER_PATH="$OUTPUT_PATH/$FOLDER_NAME"

mkdir -p "$FOLDER_PATH"

######################
####   Do Work    ####
######################

cp /c/Windows/Logs/WindowsUpdate/* "$FOLDER_PATH"
cat /c/Windows/Logs/CBS/CBS.log > "$FOLDER_PATH/CBS.log"
cp /c/ProgramData/USOShared/Logs/* "$FOLDER_PATH"

PowerShell.exe -command "Get-WindowsUpdateLog -LogPath \"$FOLDER_PATH/WindowsUpdate.log\""
cat "$FOLDER_PATH/WindowsUpdate.log"

Oracle SQL Utility Script for Unlock of All Accounts and Removal of Password Expiration

I’ve gotten tired of dealing with this on various development databases so I wrote a script to automagically remove password expiration and unlock all schema accounts.

Below is the script – verified working as of Oracle 12c

declare
sql_statement varchar2(4000);

BEGIN
  FOR profileObject IN (select DISTINCT profile from DBA_USERS)
  LOOP
    BEGIN
        sql_statement := ' alter profile ' || profileObject.PROFILE || ' limit password_life_time UNLIMITED';
        execute immediate sql_statement;
        dbms_output.put_line('SQL Statement Succeeded - ' || sql_statement);
    COMMIT;
    EXCEPTION
    when others then 
        dbms_output.put_line('SQL Statement Failed - ' || sql_statement);
    END;
  END LOOP;
  
  FOR sysUserObject IN (select * from sys.user$)
  LOOP
    BEGIN
        sql_statement := 'ALTER USER ' || sysUserObject.name ||' IDENTIFIED BY VALUES '''|| sysUserObject.spare4 ||';'|| sysUserObject.password || '''';
        execute immediate sql_statement;
        dbms_output.put_line('SQL Statement Succeeded - ' || sql_statement);
    COMMIT;
    EXCEPTION
    when others then 
        dbms_output.put_line('SQL Statement Failed - ' || sql_statement);
    END;
  END LOOP;
  
  FOR userObject IN (select DISTINCT USERNAME from DBA_USERS)
  LOOP
    BEGIN
        sql_statement := 'alter user ' || userObject.USERNAME || ' account unlock';
        execute immediate sql_statement;
        COMMIT;
        dbms_output.put_line('SQL Statement Succeeded - ' || sql_statement);
        EXCEPTION
        WHEN OTHERS THEN dbms_output.put_line('SQL Statement Failed - ' || sql_statement);
    END;
  END LOOP;
  COMMIT;
END;