Posts

Showing posts from March, 2023

Shell script to find out aliases and import new cert in jdk

 #!/bin/bash # Function to display the available aliases in the cacerts file function display_aliases {     printf "Available aliases in $cacerts_path:\n"     keytool -list -keystore $cacerts_path -storepass changeit | grep "Alias name:" | sed 's/^.*Alias name: //' } # Function to import a certificate into the cacerts file function import_certificate {     printf "Enter the path to the certificate file: "     read cert_path     printf "Enter an alias for the certificate: "     read cert_alias     cd cacerts cacerts_bkp     keytool -import -alias $cert_alias -file $cert_path -keystore $cacerts_path -storepass changeit     printf "Certificate imported with alias $cert_alias.\n" } # Function to delete a certificate from the cacerts file function delete_certificate {     printf "Enter the alias of the certificate to delete: "     read cert_alias     keytool -delete -a...

shell script that uses the openssl command to retrieve the certificate of an external site through a proxy

  #!/bin/bash # Set the proxy server details PROXY_HOST="proxy.example.com" PROXY_PORT="8080" PROXY_USER="proxy_username" PROXY_PASS="proxy_password" # Set the URL of the site to retrieve the certificate for SITE_URL="www.example.com" # Set the path to the output file for the certificate CERT_FILE="example.com.crt" # Set the OpenSSL configuration file for the proxy PROXY_CONFIG=$(cat << EOF [proxy] http_proxy = http://$PROXY_USER:$PROXY_PASS@$PROXY_HOST:$PROXY_PORT https_proxy = https://$PROXY_USER:$PROXY_PASS@$PROXY_HOST:$PROXY_PORT EOF ) # Create a temporary OpenSSL configuration file for the proxy echo "$PROXY_CONFIG" > proxy.conf # Use the OpenSSL command to retrieve the certificate for the site through the proxy openssl s_client -connect $SITE_URL -servername $SITE_URL -proxy $PROXY_HOST:$PROXY_PORT -proxy_type http -showcerts </dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' ...

Shell script to find out aliases and their expiration in cacerts

  #!/bin/bash # Set the path to the Java installation directory JAVA_HOME="/opt/java" # Set the password for the keystore KEYSTORE_PASS="keystore_password" # List all aliases in the keystore ALIASES=$(keytool -list -v -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass $KEYSTORE_PASS | grep "Alias name:" | awk '{print $3}') # Loop through the aliases and get the expiration date for each certificate for ALIAS in $ALIASES; do     # Get the expiration date in human-readable format     EXP_DATE=$(keytool -list -v -alias $ALIAS -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass $KEYSTORE_PASS | grep "Valid from" | awk '{print $3 " " $4 " " $7 " " $6}')     # Print the alias name and expiration date     echo "Alias Name: $ALIAS"     echo "Expiration Date: $EXP_DATE"     echo "" done Replace "/path/to/java" with the path to your Java installation directory, ...

Shell script to create self singed certificate for ibm http server by using gsk

  #!/bin/bash # Define variables KDB_PATH="/tmp/kdb.kdb" KDB_PASSWORD="password" CER_PATH="/tmp/cert.cer" # Prompt for certificate details printf "Enter the certificate label: "  read CERT_LABEL printf "Enter the certificate subject (e.g. /C=US/ST=California/L=San Francisco/O=Your Organization/CN=Your Domain): "  read CERT_SUBJECT printf "Enter the certificate expiration (in days): "  read CERT_EXPIRATION # Create a new kdb file ./gsk8capicmd_64 -keydb -create -db $KDB_PATH -pw $KDB_PASSWORD -stash # Generate a self-signed certificate ./gsk8capicmd_64 -cert -create -db $KDB_PATH -pw $KDB_PASSWORD -label $CERT_LABEL -dn "$CERT_SUBJECT" -size 2048 -expire $CERT_EXPIRATION # Extract the .cer file ./gsk8capicmd_64 -cert -extract -db $KDB_PATH -pw $KDB_PASSWORD -label $CERT_LABEL -target $CER_PATH

Shell script to raise csr by using openssl

 #!/bin/bash # Set variables CA_SERVER="ca.example.com" CA_PORT="443" CA_USERNAME="username" CA_PASSWORD="password" CSR_FILE="mydomain.csr" CERT_FILE="mydomain.crt" KEY_FILE="mydomain.key" # Prompt user for certificate details printf "Enter the common name (e.g. example.com): " read COMMON_NAME printf "Enter the two-letter country code (e.g. US): " read COUNTRY printf "Enter the state or province name: " read STATE printf "Enter the locality or city name: " read LOCALITY printf "Enter the organization name: " read ORGANIZATION printf "Enter the organizational unit name: " read ORG_UNIT # Generate private key openssl genrsa -out "$KEY_FILE" 2048 # Create CSR openssl req -new -key "$KEY_FILE" -out "$CSR_FILE" -subj "/C=$COUNTRY/ST=$STATE/L=$LOCALITY/O=$ORGANIZATION/OU=$ORG_UNIT/CN=$COMMON_NAME" echo "CSR generated a...

Script to search for errors in the logs of all the JVM and send mail

  the script to search for errors in the logs of all the JVMs. Here's an example of how you can modify the script: #!/bin/bash # Set the path to the logs directory LOGS_DIR="/logs/servers" # Set the email address to send notifications to EMAIL_ADDRESS="user@example.com" # Search the logs directory for SystemOut.log files and check for errors for log_file in $(find $LOGS_DIR -name "SystemOut.log"); do   # Search the log file for errors   ERRORS=$(grep -E "(ERROR|FATAL)" $log_file)   # If errors are found, send an email notification   if [ -n "$ERRORS" ]; then     echo "$ERRORS" | mail -s "Error found in WebSphere SystemOut.log for $log_file" $EMAIL_ADDRESS   fi done Save the above script to a file, for example, check_websphere_logs.sh and make it executable using the chmod command: chmod +x check_websphere_logs.sh To run the script, simply execute it from the command line: ./check_websphere_logs.sh The script will...

Linux commands that are frequently used by middleware administrators

 top: This command shows you the processes that are currently running on your system, along with their resource usage, such as CPU and memory usage. ps: This command is used to display information about the active processes on your system, including their process ID (PID), status, and resource usage. netstat: This command is used to display information about active network connections and open ports on your system. df: This command displays the amount of free and used disk space on your system's file systems. grep: This command is used to search for a specific pattern or text string in a file or output. tail: This command is used to display the last few lines of a file or output. less: This command allows you to view and scroll through the contents of a file, similar to the "more" command, but with more advanced features. find: This command is used to search for files or directories on your system based on various criteria, such as name, size, or modification date. chmod:...

Change admin console password in websphere

#!/bin/sh # Set the necessary environment variables was_home="/opt/IBM/WebSphere/AppServer" export PATH=$PATH:$was_home/bin export JAVA_HOME=/usr/java8_64 # Prompt the user to enter the current and new passwords printf "Enter the current password for admin: " stty -echo read old_password stty echo echo "" printf "Enter the new password for admin: " stty -echo read new_password stty echo echo "" # Connect to the running WebSphere Application Server instance ./wsadmin.sh -lang jython -f changepassword.py "$old_password" "$new_password" exit 0 This script uses the printf command to display the prompt message to the user. The stty command is used to temporarily turn off echo mode when reading the password input. The changepassword.py file should  contain content the same wsadmin commands as before: import sys # Get the old and new passwords from command line arguments old_password = sys.argv[0] new_password = sys.argv[1]...

How to resolve port conflict in websphere

 To resolve port conflicts in WebSphere Application Server on Linux, you can follow the below steps: Determine the port that is in conflict: a. Login in server b. Run the command: ./netstat -an | grep <port> where <port> is the port number that is in conflict. Identify the process that is using the port: a. Run the command: ps -ef | grep <PID> where <PID> is the Process ID (PID) of the process that is using the port. Stop the process that is using the port: a. Use the kill command to stop the process: kill -9 <PID> where <PID> is the Process ID of the process that is using the port. b. Change port in serverindex.xml file if required  c.Stop node and sync with dmgr then start node Restart the WebSphere Application Server: a. Go to the WebSphere installation directory: cd /opt/IBM/WebSphere/AppServer/bin b. Run the command: ./stopServer.sh <server_name> where <server_name> is the name of the server that you modified the port number...

DerInputStream class is available in rt.jar and ibmpkcs.jar in Websphere

  The DerInputStream class is a part of the Java Cryptography Extension (JCE) API and is typically included in the rt.jar file of the Java runtime environment. As for Websphere, the ibmpkcs.jar file is an IBM-provided package that contains classes for PKCS-related functionality, including the DerInputStream class. So it is possible that the DerInputStream class is available in both rt.jar and ibmpkcs.jar in Websphere, depending on the specific version and configuration of Websphere being used. To import the com.ibm.security.util.DerInputStream class in your Java program, you can use the following import statement: import com.ibm.security.util.DerInputStream; Note that in order to use this class, you need to have the IBM Security Provider JAR file (ibmpkcs.jar) in your classpath. You can download this JAR file from the IBM website or obtain it from your Websphere installation directory. Once you have added the JAR file to your classpath, you should be able to import and ...

shell script to import certificate in cacerts of JDK

#!/bin/bash # Set the path to the cacerts file CACERTS_FILE="${JAVA_HOME}/jre/lib/security/cacerts" # Prompt for the path to the certificate file printf "Enter path to certificate file: " read CERT_PATH # Prompt for the alias for the certificate in the keystore printf "Enter alias for certificate: " read CERT_ALIAS # Prompt for the keystore password printf "Enter keystore password: " read -s PASSWORD echo # Import the certificate into the cacerts file keytool -importcert -alias "${CERT_ALIAS}" -file "${CERT_PATH}" -keystore "${CACERTS_FILE}" -storepass "${PASSWORD}" # Verify the certificate was imported successfully keytool -list -v -keystore "${CACERTS_FILE}" -storepass "${PASSWORD}" | grep "${CERT_ALIAS}" In this version of the script, we prompt the user to enter the path to the certificate file, the alias for the certificate in the keystore, and the keystore password using t...

shell script to scp multiple file to multiple destinations

  #!/bin/bash # Prompt the user for the name of the file to transfer using printf and read commands printf "Enter the name of the file to transfer: " read filename # Prompt the user for the IP addresses to transfer the files to using printf and read commands printf "Enter the IP addresses to transfer the file(s) to (separated by spaces): " read -a ips # Define the username to use for the SCP transfer username="user" # Loop through the array of IP addresses and transfer the file to each one for ip in "${ips[@]}" do     # Use printf to display a message before transferring each file     printf "Transferring %s to %s...\n" "$filename" "$ip"         # Use scp to transfer the file to the current IP address     scp "$filename" "${username}@${ip}:~/" done # Use printf to display a summary message when the transfers are complete printf "Transferred %s to %d IP addresses.\n" "$filename"...

shell script to retrieve ssl certificate by using openssl s_client

 shell script to retrieve ssl certificate by using openssl client #!/bin/bash # Function to retrieve certificate for a given hostname and port function get_cert {   HOSTNAME="$1"   PORT="$2"   # Retrieve the certificate and extract the end-entity certificate   CERT=$(echo | openssl s_client -showcerts -servername "$HOSTNAME" -connect "$HOSTNAME":"$PORT" 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sed -n '1,/END CERTIFICATE/p')   # Save the certificate in PEM format to a file   echo "$CERT" > site_cert.pem   echo "Certificate for $HOSTNAME:$PORT saved to site_cert.pem" } # Array of sites and corresponding ports SITES=(   "example.com:443"   "google.com:443"   "yahoo.com:443"   "github.com:443"   "reddit.com:443"   "twitter.com:443"   "linkedin.com:443"   "stackoverflow.com:443" ) # Print the l...

Common 301 Redirect Htaccess Rules

Here are some common 301 redirect rules that can be added to an .htaccess file: Redirect a single page: Redirect 301 /old-page.html http://www.example.com/new-page.html This rule redirects the old page "/old-page.html" to the new page "http://www.example.com/new-page.html". Redirect an entire domain: Redirect 301 / http://www.newdomain.com/ This rule redirects all pages on the old domain to the home page of the new domain. Redirect a directory: RedirectMatch 301 ^/old-directory/(.*)$ http://www.example.com/new-directory/$1 This rule redirects all pages in the old directory "/old-directory/" to the corresponding pages in the new directory "/new-directory/". The "$1" is a backreference to the part of the URL that matches the "(.*)" pattern. Redirect all non-www requests to www: RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.example\.com$ RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] This rule redirects ...