Code Snippet

Just another Code Snippet site

Random Post :




[Oracle] Enable partitions

Check if partitionning is enabled or not :

select * from v$option where parameter like '%Partition%';

To enable partition feature :

cd $ORACLE_HOME/rdbms/lib
make -f ins_rdbms.mk part_on
make -f ins_rdbms.mk ioracle

On Solaris, ‘make’ could be installed using following packages :

  • make
  • libgcc
  • libintl
  • libiconv
  • libintl-3.4.0-sol10-x86-local
    make-3.82-sol10-x86-local
    libiconv-1.14-sol10-x86-local
    libgcc-3.3-sol10-intel-local

    , , , ,

    [How-To] SSH

    SSH to a machine using an SSH bastion (proxy)

    ssh -o ProxyCommand="ssh -W %h:%p -q BASTION_USER@BASTION_SERVER" FINAL_USER@FINAL_SERVER
    

    for example :

    ssh -o ProxyCommand="ssh -W %h:%p -q root@10.2.3.88" fusion@svc-1
    

    and with additional SSH options :

    ssh -o ProxyCommand="ssh -W %h:%p -q -p 8022 -oHostKeyAlgorithms=+ssh-dss root@10.2.3.88" -oHostKeyAlgorithms=+ssh-dss fusion@svc-1
    

    —-
    SSHPass

    sshpass -p password ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null user@target 
    

    Execure command as ssh (using SSH PASS)

    sshpass -p password ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null user@target whoami
    sshpass -p password ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null user@target cat /etc/hosts
    sshpass -p password ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null user@target 'sed -i ...'
    

    , , ,

    [Java] Generate hash code from a file

    /**
     * Generate a hash for a file.
     */
    public final class HashUtils {
    
        /** Default hash algorithm. */
        public static final Algo DEFAULT_ALGO = Algo.MD5;
    
        /**
         * Define all hash algorithm.
         */
        public enum Algo {
            /** MD5. */
            MD5("MD5"),
            /** SHA1. */
            SHA1("SHA-1"),
            /** SHA256. */
            SHA256("SHA-256"),
            /** SHA384. */
            SHA384("SHA-384"),
            /** SHA512. */
            SHA512("SHA-512");
    
            private String value;
    
            /**
             * Default constructor.
             * 
             * @param name
             *            of the algo
             */
            Algo(final String name) {
                value = name;
            }
    
            /**
             * @return the value
             */
            String getValue() {
                return value;
            }
    
            /**
             * Set the value.
             * 
             * @param name
             *            of the value to set
             */
            void setValue(final String name) {
                value = name;
            }
        };
    
        /**
         * Default private constructor.
         */
        private HashUtils() {
    
        }
    
        /**
         * Return hash representation of the file content. (using default algorithm)
         * 
         * @param filename
         *            name of the file to hash
         * @return hash representation of the file
         * @throws Exception
         *             in case of error
         */
        public static String getChecksum(final String filename) throws Exception {
            return getChecksum(filename, DEFAULT_ALGO);
        }
    
        /**
         * Return hash representation of the file content. (using specific algorithm)
         * 
         * @param filename
         *            name of the file to hash
         * @param algo
         *            used to hash the file
         * @return hash representation of the file
         * @throws Exception
         *             in case of error
         */
        public static String getChecksum(final String filename, final Algo algo) throws Exception {
            byte[] b = createChecksum(filename, algo);
            String result = "";
            for (int i = 0; i < b.length; i++) {
                result += Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1);
            }
    
            return result;
        }
    
        /**
         * Read and parse file to hash.
         * 
         * @param filename
         *            name of the file to hash
         * @param algo
         *            used to hash the file
         * @return byte array representing hash
         * @throws Exception
         *             in case of error
         */
        private static byte[] createChecksum(final String filename, final Algo algo) throws Exception {
            InputStream fis = new FileInputStream(filename);
            byte[] buffer = new byte[1024];
            MessageDigest complete = MessageDigest.getInstance(algo.getValue());
            int numRead;
            do {
                numRead = fis.read(buffer);
                if (numRead > 0) {
                    complete.update(buffer, 0, numRead);
                }
            } while (numRead != -1);
            fis.close();
            return complete.digest();
        }
    }
    

    Previous Posts Next posts