Showing posts with label SSH. Show all posts
Showing posts with label SSH. Show all posts

Sunday, September 12, 2010

X11 Forwarding in SSH for Solaris and Linux

You might be wonder what is fun in this blog looking for X11 forwarding on Solaris 5.10!! You might be excited to see the beauty of colorful Oracle Fusion Middleware WebLogic 11g installation window when you executable binaries (wls1033_solaris32.bin), You might wish to see Oracle WebLogic domain configuration Wizard (config.sh), Oracle WebLogic Domain Template builder(config_builder.sh), BEA Smart Update (bsu.sh) windows or your Oracle Database 11g while you work on a remote UNIX machines.

After spending few hours on the Internet found many blogs written on their experiences, few document on websites, which illustrated about SSH, X11 forwarding in UNIX. I understand that what I need to do? To achieve my objective X11 Forwarding using SSH window, I must have a X emulating software installed on my desktop. you guys have this on your desktop?? If not install Hummingbird Connectivity (Xming is alternative)

My experimenting environment is Solaris 10, Oracle WebLogic, SSH (You can use Putty also), Hummingbird Connectivity (Xming is alternative)

Applicable to:
This you can use for any Java AWT or Swing programs in any UNIX based Operating environment.
You might download free Hummingbird Software also providing evaluation version who want to test their environment.

Here I am sharing with smart guys WLA/DBA my version of brain storming on this. When I first-time tried to invoke X window command it rejected and told as shown below:

No X11 DISPLAY variable was set, but this program performed an operation which requires it.

I had updated DISPLAY variable as follows

$ export DISPLAY=localhost:11.0

My first experiment with normal UNIX user
When I executed bsu.sh script I got the following in Normal UNIX user:

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class
sun.awt.X11GraphicsEnvironment
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
at sun.awt.X11.XToolkit.(XToolkit.java:89)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at java.awt.Toolkit$2.run(Toolkit.java:834)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:826)
at sun.swing.SwingUtilities2$AATextInfo.getAATextInfo(SwingUtilities2.java:126)
at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults(MetalLookAndFeel.java:1556)
at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults(BasicLookAndFeel.java:130)
at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults(MetalLookAndFeel.java:1591)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:541)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:581)
at javax.swing.UIManager.initializeDefaultLAF(UIManager.java:1343)
at javax.swing.UIManager.initialize(UIManager.java:1432)
at javax.swing.UIManager.maybeInitialize(UIManager.java:1420)
at javax.swing.UIManager.getDefaults(UIManager.java:660)
at javax.swing.UIManager.put(UIManager.java:989)
at com.bea.plateng.common.ui.gui.GUIHelper.initPLAF(GUIHelper.java:69)
at com.bea.plateng.patch.gui.PatchGUIHelper.startGui(PatchGUIHelper.java:90)
at com.bea.plateng.patch.Patch.main(Patch.java:338)

My UNIX admin buddy told that dear, first try with xclock then go for other, then I thought Ohhh!! that's good idea, let me try that...

$ xclock
bash: xclock: command not found

Hmmmmmmm!!, what is this? Think, Think Think!!!, On a Solaris 5.10 you can find some of the commands in OpenSource folder, Let me try in that path this xclock on the following path.
/usr/openwin/bin/xclock

No luck buddy, same kind of error message as bsu.sh got above.

Now I realized and verified all those PATH, CLASSPATH are pointing to proper JAVA_HOME/bin, lib paths respectively, one of them is misconfigured reset to correct path.

One of Sun blog saying about Updating $Home/.ssh/config file as follows:

Host *
ForwardX11 yes
ForwardAgent no

After doing this I had ran the following:

$ ssh -X user@hostname

This is the command will activallte the X emulation on your UNIX machine with given SSH configuration. Actually it will refer to the default configuration /etc/.ssh/config but when you create new config file on your user home directory it will prefer to execute for your user settings. This command also updates .Xauthority file when you ssh -X command.

Verified every step again finally I got X window for xclock

Hey!! Cheerup on my face!!

Experiment 2: LDAP user logon with assume user name as 'pavanwla', switched to role 'wladmin'. I started trying on it for X11 forwarding. First Let me try, xclock on

-->

[wladmin@hostname~]$ /usr/openwin/bin/xclock
Error: Can't open display:

Ohh its same DISPLAY variable problem right? You remember it!!

[wladmin@hostname~]$ export DISPLAY=localhost:10.0
[wladmin@hostname~]$ echo $DISPLAY
localhost:10.0

Let me try now, what it will say...

[wladmin@hostname~]$ /usr/openwin/bin/xclock
X connection to localhost:10.0 broken (explicit kill or server shutdown)

Oh My Gash!!! what to do now????????????
After a while, I bugged again my buddy Mr. Unix Admin about this. He told that configurations, X emulating authoriy must match ldap user and role. Now my turn, first I tried to get xclock on ldap user, that confirms everything fine at ldap user level. This configuration, Xauthority I can use in role user too, then see what I did:

[wladmin@hostname~]$ scp pavanwla@hostname:/home/pavanwla/.ssh/config .ssh/
[wladmin@hostname~]$scp pavanwla@hostname:/home/pavanwla/.Xauthority .

Started ssh session with ssh -X command.

Finally, the climax came to end, xclock started. ahh!!
Reference:

https://cygwin.com/setup-x86_64.exe
http://sourceforge.net/projects/xming/files/Xming/6.9.0.31/Xming-6-9-0-31-setup.exe/download
http://download.oracle.com/docs/cd/E15051_01/common/smartupdate/guide/quickrefax.html

Wednesday, July 7, 2010

Copying to multiple remote machines

Here is another interesting story of WLA (of-course mine), When I visited US in 2007 there was lot of restrictions in work places. "Hey its production you know what happen if you touch it??" "Don't open this files", "Don't enter into that folders", it will be dangerous... I know that very well what is missing in the system, where it is required a change but my hands kept criss cross!!

Days passed I got opportunity to come again on long term. Now, the whole new System is going shapeup with my hands. The system is awaiting for me since long days. :) All those sparkling colorful ideas running around my mind, got chance to flow onto the system to form various automated scripts, which are having little in size with greater capabilities.

Whenever there is a application version release the archive files(.jar, .war, .ear) need to copied to all over the remote machines. In olden days we were using 'sftp' command and its related 'put', 'mput', 'get' and 'mget' commands to complete the task. Manually double checking wheather the copying is done correct or not, by verifying in each machine content by comparing the each file sizes. Here I found a flaw that there could be chance of human error. While understanding 'Six Sigma Course', where I learnt about human errors makes greater defect to many customer's business. To avoid this better option is automation of the task as possible as much.I remembered Mr. Neil Gogte words about "Cyber Coolie". The software engineer who works as per his contractor asked him to do only those things he will do. Never think other than the work which is assigned to him. My soul shouts out 'NO!!', I cannot be a Cyber coolie any more !!

My beautiful sparkling colorful ideas SSH password less connection to multiple remote machines, powerful bright idea of 'scp' command usage with verification option built within a script come out as a wonderful shell script, which had mighty power of built-in checking with no chances of human error. When I show the execution of this script to my teammates they are very happy and appreciated me. Many productive hours are saved though this activity was disturging to other regular job. The script made almost hands free task!! Finally, That's the way team turn happy ever by using the easy script.

Script is :
TADAA!!!!!!!!!!

# Define variables values
src=
target=
hostlist=
user=
Logfile=

#=== script logic starts here ====
if [ -d $src ]
then
echo "Code folder found, preparing to transfer\n"
while read server
do
result=scp -r $src $user@${server}:$target
if [ $result -eq 0 ]
then
echo $server transfer done >> $Logfile
else
echo $server transfer failed.
exit
fi
done < $hostlist
else
echo "Code folder \"$src\" not found\n"
fi

Tuesday, June 29, 2010

Monitoring CPU Load Averages with Shell Script

Today I started re-inventing myself, started looking what all I did for me and my team to perform in better ways. Remembered those we used to open UNIX SSH windows to monitor How the CPU load average in each site. While doing this monitoring activity on site1, there might be possible that some other site reach to overload, which leads to uncontrol tendency to work. It was funny, my dear buddy named it as 'Barbar work!!' :)

After little R & D on Google/Internet found few suitable solutions. I had chosen 'uptime' command running with remote SSH connection in a loop. Adding more value to this sending a mail on the event of crossing the threshold value. This threshold will be vary depending upon the application and CPU power. Trail and error make you to identify what could be the threshold. Defining these threshold values Venu GopalRao helped a lot. Once script started working he was amazed and appreciated as well.

This script can be run forever with a specified time interval. You can use 'at' command or 'crontab' also for this task. I prepared a 'bash' script that could work for Solaris and also on Linux.

Before to this script we need to establish the password less connection to all the remote machines with 'key-gen' command. Public key authentication, which is the good choice password less connecting remote UNIX machines. Here, you can use any choice for encryption algorithms such as RSA, DSA etc.,


Customization/Cosmotics to this script
When you run this script at your prompt you can see the high load average server details in red color which makes sense to act up on that quicker. All server list I had kept in a plan text file and accessed it line by line as array for looping.

#!/bin/bash
#======================================================
# This script will check CPU Load, network ping status
# and also checks diskspace on every machine
#======================================================
RECIPIENTS="pavanwla@yahoo.co.in"
LOG=./load.log
 
check_load()
{
        loadnow=`echo $msg| cut -d, -f4 | cut -d: -f2 | cut -d. -f1`
        d=`echo $msg |awk '{print $((NF-1))}'`
        SD=`date "+%Y-%h-%d@%H:%M:%S"`
        echo $SD '****'
        if [ $loadnow -gt 14 ]; then
                echo -e ' \033[31m' $server ' ' $loadnow '\033[m'>>$LOG
                echo $SD $server ' ' $loadnow |mailx -s LOAD_WARN $RECPIENTS
        elif [ $loadnow -gt 19 ]; then
                echo -e ' \033[31m' $server ' ' $loadnow '\033[m'>>$LOG
                echo $SD $server ' ' $loadnow |mailx -s LOAD_CRITICAL $RECPIENTS
        else
                echo -e $server '\t' $loadnow '\t' $p '\t'$d >>$LOG
        fi
}

#==============================================================
#                 M A I N  S C R I P T
#==============================================================
if [ -f $LOG ]
then
        rm $LOG
fi
serlist=`cat prodServers.txt`
echo -e "========================================================">>$LOG
echo -e "  HOSTNAME  CPU Load     Network status       Disk Space">>$LOG
echo -e "========================================================">>$LOG
 
for server in $serlist
do
        echo 'connecitng to ' $server
        msg=`ssh $server "uptime; df -k /app|grep app |awk '{print \$5}'"`
        p=`ping -s $server 56 2 |grep loss | awk -F',' '{ print $3 }'`
        check_load
done
cat load.log
Please make sure that you must have prodServers.txt file in the same script path. Sample prodServers.txt file as follows:
myprod.server1.com
myprod.server2.com
...
myprod.server20.com
Upgrade Script
Adding more flavor to the load average script finding the disk space on every machine and also verifying network connectivity that ping response to every machine. Initially, I made it with two ssh commands one is for finding load average on each remote machine, other one is to check disk space on each machine. But it is not a good scripting way. With the help of the linkedin discussion I have updated it to single ssh command so that it will process faster by making less ssh sessions.

What is Next step??
If you find CPU load average is going above the threshold then you need to prepare yourself alert. Open that concern UNIX machine and find the causing process on that machine with 'top' command or 'prstat -L -a ' command options respective UNIX environment.

Take the Thread dumps of that culprit java process id of WebLogic instance. If CPU load reaching more than threshold then terminate that process/instance.
Analyze why that time CPU load gone high what thread were doing that time.

Note: This script created and executed on Solaris which remotely connects Linux and Solaris machines.

Good Forum Reference:
1. Linkedin Discussion
2. http://www.daniweb.com/forums/thread48764.html">Shell Script for Load monitoring!

Comments are most welcome!! HAPPY TO HELP!!

Blurb about this blog

Blurb about this blog

Essential Middleware Administration takes in-depth look at the fundamental relationship between Middleware and Operating Environment such as Solaris or Linux, HP-UX. Scope of this blog is associated with beginner or an experienced Middleware Team members, Middleware developer, Middleware Architects, you will be able to apply any of these automation scripts which are takeaways, because they are generalized it is like ready to use. Most of the experimented scripts are implemented in production environments.
You have any ideas for Contributing to a Middleware Admin? mail to me wlatechtrainer@gmail.com
QK7QN6U9ZST6