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;

Git Push Fails – fatal: The remote end hung up unexpectedly

Had this issue today and found the below solution.

Credit to Atlassian for documenting – I am reposting and archiving the fix for my own records.

https://confluence.atlassian.com/staskb/git-push-fails-fatal-the-remote-end-hung-up-unexpectedly-282988530.html

Symptoms

When users try to run “git push” the following error message is shown:

$ git push
Counting objects: 2332669, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (360818/360818), done.
error: RPC failed; result=22, HTTP code = 411
fatal: The remote end hung up unexpectedly
Writing objects: 100% (2332669/2332669), 483.30 MiB | 114.26 MiB/s, done.
Total 2332669 (delta 1949888), reused 2330461 (delta 1949349)
fatal: The remote end hung up unexpectedly

Cause

The “Smart HTTP” protocol in Git uses “Transfer-Encoding: chunked” in POST requests when it contains packed objects greater than 1MB in size.

Some proxy servers, like Nginx, do not support this transfer encoding by default, and the requests will be rejected before they get to Stash. Because of this, the Stash logs will not show any extra information.

Workaround

  • When pushing a large amount of data (initial push of a big repository, change with very big file(s)) may require a higher http.postBuffer setting on your git client (not the server). From https://www.kernel.org/pub/software/scm/git/docs/git-config.htmlhttp.postBufferMaximum size in bytes of the buffer used by smart HTTP transports when POSTing data to the remote system. For requests larger than this buffer size, HTTP/1.1 and Transfer-Encoding: chunked is used to avoid creating a massive pack file locally. Default is 1 MiB, which is sufficient for most requests.
  • Configuration on your reverse proxy. Usually ngnix the parameter client_max_body_size is a blocker. The reverse proxy may also have a connection timeout that’s closing the connection (e.g. TimeOut or ProxyTimeout in apache, proxy_read_timeout in ngnix). Try bypassing the proxy by pushing directly to Stash IP:port. If this works, it’s highly likely that the proxy server is causing the early disconnect and needs to be tuned.
  • User is using an outbound proxy on his machine that is causing the issue.

Resolution

Finding the Process that has a Lock on a File when you don’t have Administrator

Most of the time Microsoft Windows experts will immediately point you to Sysinternals Process Explorer. Unfortunately for a vast majority of us, this requires Administrator privileges on your machine and in today’s security conscious society, System Admin give this out less and less.

Enter this solution I found from Stack Overflow user Svish.

The following is a direct copy paste of the post that you can find at this link for citation purposes.

You can use the Resource Monitor for this which comes built-in with Windows 7, 8, and 10.

  1. Open Resource Monitor, which can be found
    • By searching for Resource Monitor or resmon.exe in the start menu, or
    • As a button on the Performance tab in your Task Manager
  2. Go to the CPU tab
  3. Use the search field in the Associated Handles section
    • See blue arrow in screen shot below

When you’ve found the handle, you can identify the process by looking at the Image and/or PID column.

You can then try to close the application as you normally would, or, if that’s not possible, just right-click the handle and kill the process directly from there. Easy peasy!

Resource Monitor screenshot

Example for Sending Commands to a Currently Active Screen Session

If you are one of the people that use my Docker VPN Tunneling Tool this can be used to automate login by appending it to your portion of the script.

^M represents pressing enter if unfamiliar. I’ll probably forget, that’s why I’m creating this post.

#sh dockerVpnTool.sh $OPENCONNECT_VPN_ENDPOINT $LOCAL_DOCKER_ADDRESS $LOCAL_DOCKER_SSH_PORT $CONTAINER_NAME $IMAGE_NAME "$(declare -p DESTINATION_LIST)"

#Begin Customization
echo -e "\n\n1\n" | ./dockerVpnTool.sh $OPENCONNECT_VPN_ENDPOINT $LOCAL_DOCKER_ADDRESS $LOCAL_DOCKER_SSH_PORT $CONTAINER_NAME $IMAGE_NAME "$(declare -p DESTINATION_LIST)"

function connectToEndpoint()
{
    #Begin Endpoint Customization 
    COMMAND_TO_RUN="winpty docker exec $CONTAINER_NAME bash -c"
    COMMAND_TO_RUN_INTERACTIVE="winpty docker exec -it $CONTAINER_NAME bash -c"

    SESSION_NAME="session_vpnTool"
    USERNAME='username'
    PASSWORD='password'
    CONNECTION_PROFILE='connectionProfile'

    $COMMAND_TO_RUN "screen -d -m -S $SESSION_NAME openconnect $OPENCONNECT_VPN_ENDPOINT"
    $COMMAND_TO_RUN "screen -S $SESSION_NAME -p 0 -X stuff \"$CONNECTION_PROFILE^M\""
    $COMMAND_TO_RUN "screen -S $SESSION_NAME -p 0 -X stuff \"$USERNAME^M\""
    $COMMAND_TO_RUN "screen -S $SESSION_NAME -p 0 -X stuff \"$PASSWORD^M\""

    #If Debug is Needed
    #$COMMAND_TO_RUN_INTERACTIVE "screen -r"
}

connectToEndpoint

Understanding Question Mark and Colon Operators in Java Programming

Today I was having issues understanding syntactically how ? and : operators work in Java on some legacy code I was reading. The issue was that all definitions I found through google practically sucked until I found this one by “cricket_007” on StackOverflow.

Either way, I got it figured out and am documenting this and raising awareness for other developers in the future.

Thanks so much “cricket_007” and here is the link if anyone is interested:

Custom SendTo Execution Shortcuts – Windows

Start out with doing “Windows Key + R” and type “shell:sendto”

Next, this folder will pop up:

Create a new Batch File in this directory – I’ve called mine “Launch with Bash.bat” – below is some example code:

@ECHO OFF
SETLOCAL

SET filedrive=%~d1
SET filepath=%~p1
SET filedrive_and_filepath=%filedrive%%filepath%

SET filename=%~n1
SET fileextension=%~x1
SET filename_and_fileextension=%filename%%fileextension%

cd /d %filedrive_and_filepath%
"C:\Program Files\Git\bin\bash.exe" -c "sh ""%filename_and_fileextension%"" "

Note a few things – Batch files can take a starting argument like methods in programming so basically when you right click and do “SendTo” on Windows, it sends the filepath of what you are “Sending” to whatever the destination is.

In a batch file, these parameters are accessed through %1 %2 %3 etc for each positional parameter that is being passed to the “method”

This prewritten file will allow you to create a custom process that easily allows you to launch something with a programmatic process. AKA custom builds, processes, launch parameters, etc.

Quick Docker Import/Export Utilizing gzip for Compression

IMAGE_NAME="repository:image_tag"
OUTPUT_FILE="/path/to/imageOutput.tar.gz"
#docker load < $OUTPUT_FILE
#docker save $IMAGE_NAME | gzip -c > $OUTPUT_FILE

The above snippet keeps replacing the docker save line with the escaped version as &gt instead of >

AKA ->

IMAGE_NAME=”repository:image_tag”
OUTPUT_FILE=”/path/to/imageOutput.tar.gz”
#docker load < $OUTPUT_FILE
#docker save $IMAGE_NAME | gzip -c > $OUTPUT_FILE

Bash Script for Automatic Creation and Generation of Public Private Key for Linux Server Login

Wrote this quick blurb so I never have to do this process again.

The general idea is to take the output that is created on the screen, copy and paste it to a file somewhere on your computer, and either use it as is with your environment ssh configuration or convert it to a *.ppk for Putty.

What the script does is the following:

  1. Create the .ssh directory as the user you are currently logged in as (if it doesn’t already exist)
  2. Set necessary permissions on the directory (if it isn’t already set)
  3. Create the “authorized_keys” file (if it doesn’t already exist)
  4. Generate the Public/Private Pair
  5. Append the thumbprint to the “authorized_keys” file
  6. Output the private key for copying to Standard Out
  7. Delete the generated files for the Public/Private pair

After copying the key from the terminal screen you’ll paste it into a text file and either use it as is or convert it to a *.ppk for usage in Putty.

KEY_OWNER="Cody Garrett"
KEY_NAME="automatic.key"
KEY_NAME_PUB="$KEY_NAME.pub"
mkdir ~/.ssh
chmod 0700 ~/.ssh
touch ~/.ssh/authorized_keys
chmod 0644 ~/.ssh/authorized_keys
ssh-keygen -t rsa -b 4096 -C "$KEY_OWNER" -f "$KEY_NAME" -P ""
cat "$KEY_NAME.pub" >> ~/.ssh/authorized_keys
echo "Very Important!"
echo "The next screen that will come up will display the key needed for login."
echo "You must copy this in it's entirety in order to login using what was setup in the previous commands."
echo ""
echo "Press enter to continue..."
read
clear
echo ""
echo "##################"
echo "## Private Key: ##"
echo "##################"
echo ""
cat $KEY_NAME
echo ""
echo "###########################"
echo "## Authorized Key Entry: ##"
echo "###########################"
echo ""
cat $KEY_NAME_PUB
echo ""
rm -f "$KEY_NAME" "$KEY_NAME_PUB"

Automated Email Script in Bash

Rewrote my “Free Ice Cream” script in bash because I needed to be able to flexibly send emails without going through 20 UAC prompts due to restrictions and how many people are scared of PowerShell.

Below is my new implementation, instead of relying on Outlook (like before), this version is platform independent and will work on any OS with any Mail Client like Thunderbird or Gmail.

rawurlencode() {
  local string="${1}"
  local strlen=${#string}
  local encoded=""
  local pos c o
 
  for (( pos=0 ; pos<strlen ; pos++ )); do
     c=${string:$pos:1}
     case "$c" in
        [-_.~a-zA-Z0-9] ) o="${c}" ;;
        * )               printf -v o '%%%02x' "'$c"
     esac
     encoded+="${o}"
  done
  echo "${encoded}"
}

function generateParticipants() {
	PARTICIPANT_LIST=("$@")
	
	PARTICIPANT_STRING_TO_RETURN=""

	SEPARATOR=";"

	for PARTICIPANT in "${PARTICIPANT_LIST[@]}";
	do
		PARTICIPANT_STRING_TO_RETURN+="$PARTICIPANT"
		PARTICIPANT_STRING_TO_RETURN+="$SEPARATOR"
	done

	echo "$PARTICIPANT_STRING_TO_RETURN"
}
 
function createEmail() {
	SUBJECT="$1" # Save first argument in a variable
	shift
	BODY="$1" # Save second argument in a variable
	shift # Shift all arguments to the left (original $1 gets lost)
	TO_ARRAY=("$@")

	TO=$(generateParticipants "${TO_ARRAY[@]}")

	SUBJECT_ENCODED=$(rawurlencode "$SUBJECT")
	BODY_ENCODED=$(rawurlencode "$BODY")

	MESSAGE_OBJECT="mailto:$TO&subject=$SUBJECT_ENCODED&body=$BODY_ENCODED"
	
	echo "########################"
	echo "#### EMAIL PREVIEW: ####"
	echo "########################"
	echo ""
	echo "To: $TO"
	echo "Subject: $SUBJECT"
	echo "Body: $BODY"
	echo ""
	echo "Sending to Email Client..."
	echo ""
	echo start "" "$MESSAGE_OBJECT"
	start "" "$MESSAGE_OBJECT"
}
 
EMAIL_SUBJECT="Free Ice Cream!"
EMAIL_BODY="I'm Buying."

PARTICIPANT_LIST+=("person1@company.com")
PARTICIPANT_LIST+=("person2@company.com")
PARTICIPANT_LIST+=("person3@company.com")

createEmail "$EMAIL_SUBJECT" "$EMAIL_BODY" "${PARTICIPANT_LIST[@]}"