SSH tunnel to Oracle database

Some companies have a strict security policy to connect with a database. Mostly the acceptance or production databases are accessable trough the specific hosts and ports, but not with your client.
So, if you can connect to such host trough SSH and you are running Linux, the command below could help you:

Linux users

ssh -L 7100:dbserver:1521 user@host

dbserver => The database server where the shema’s reside.
user => The linux user which has access to the linuxhost.
host => The host which had a firewall rule to connect to the databaseserver.
7100 => Your port on your localhost machine to connect to the database. (user ports => 1024-49151)
1521 => The database server connection port.

Now you could connect your client with the database by using:
dbserver = localhost
port = 7100

Poor Micr$s$ft users

You could use Putty to create a tunnel:

putty_tunnel

 

 

 

Advertisements

Oracle Weblogic nodemanager STOP script Bash and Python

Everyone who is using Oracle Weblogic must had a thought like  “Where the *** is the stop script to kill my nodemanager proces”…. Well, i did. So i wrote a simple stop script which can be better probally, but it does the job.

#!/bin/bash
PID=`ps -efw | grep -i "Xms128m" | grep -i nodemanager | awk '{print $2}'`
if [ ! -z $PID  ]; then
  echo "Killing nodemanager with PID: $PID"
  kill $PID
  CHECK=`ps -e -o pid | grep $PID`
  if [ -z $CHECK ]; then
    echo "Nodemanager stop success"
  fi
else
  echo "No nodemanager process running"
fi

Remember to copy this snippet into a bash file and set the correct permissions.

Some developers like to stop nodemanager programmaticly. I.E.
Note: You could use it to stop and start adminservers for example…
You could use following python definitions:

# RETURN LIST OF PROCESS IDS FROM GREPING PROCESS COMMANDS
def psgrep(str):
    pat = re.compile(str)
    cmd = "ps -e -o pid,command"
    lines = shlines("ps -e -o pid,command")
    pids = []
    for line in lines:
        cols = string.split(line)
        if cols[1] == "grep": continue
        for col in cols[1:]:
            if pat.search(col):
                pids.append(cols[0])
                continue
    return pids

def stop_process_tree(ppid):
    time.sleep(1)
    pids = get_child_processes(ppid)
    while len(pids) > 0:
        for pid in pids:
            stop_process_tree(pid)
        pids = get_child_processes(ppid)
    kill_process(ppid)
    return

def kill_process(pid):
    if pid == None or pid == '':
        return
    time.sleep(1)
    if shout("ps -o pid= --pid " + pid) != '':
        os.system("kill " + pid)
    for i in range(30):
        time.sleep(1)
        if shout("ps -o pid= --pid " + pid) == '':
            return
    os.system("kill -9 " + pid)
    for i in range(30):
        time.sleep(1)
        if shout("ps -o pid= --pid " + pid) == '':
            return
    error("Cannot kill " + pid)
    return

def get_child_processes(ppid):
    return string.split(shout("ps -o pid= --ppid " + ppid))

Subversion: Delete old .svn entries

If you want to delete the hidden .svn directories with versioning information you can use following simple “one liners”
For Micr$s$ft Wind$ws you can use:
 

FOR /F "tokens=*" %%G IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q "%%G"
 


And for Linux distro’s:

 

find ./ -name ".svn" | xargs rm -Rf