Tuesday, March 1, 2016

Tuesday, November 17, 2015

Red Hat Example of installing Tomcat

# cd /tmp
# tar -xzf  apache-tomcat-6.0.29.tar.gz
# mv apache-tomcat-6 /usr/local
# cd /usr/local
# ln -s apache-tomcat-6
# yum install java-1.6-openjdk.i386 -> required package
# yum install httpd --> required package
# ls -l /usr/bin/java
# ls -l /etc/alternatives/java
# java -version
# cd /root
# vi .bash_profile
CATALINA_HOME = /usr/local/tomcat
export CATALINA_HOME
JAVA_HOME = /usr/lib/jvm/jre-1.6-openjdk
# . .bash_profile
# env | grep -i CATALINA
# env | grep -i JAVA
# cd /etc/init.d
vi tomcat
# this is the init script for starting up the tomcat server
# chkconfig:345 91 10
# description: start and stop tomcat deamon
# source function library
. /etc/rc.d/init.d/functions
#Get config
. /etc/sysconfig/network
# check that networking in up
[ "${NETWORKING}"="no"] && exit 0

tomcat = /usr/local/tomcat
startup=$tomcat/bin/startup.sh
shutdown = $tomcat/bin/shutdown.sh
export JAVA_HOME=/usr/lib/jvm/jre-1.6-openjdk

start(){  echo -n $"starting Tomcat service:"
#demon -c
$startup
RETVAL=$?
echo
}

stop(){  action  $"stopping Tomcat service:  "
$ shutdown
RETVAL = $?
echo}

restart(){
stop
start
}

## see how we were called

case "$1" in
start)  
start
;;
stop)
stop
;;
status)
#doesn't work
status tomcat
;;
restart)
restart
;;
*)
echo $"usuage : $0 {start|stop|status|restart}"
exit 1
;;

esac

exit 0

# chmod 755 tomcat
# vi /etc/sysconfig/iptables

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp --dport 8080 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -dport 80 -j ACCEPT

# service iptables restart
# chkconfig --add tomcat
# chkconfig --list | grep -i tomcat
# service tomcat start
# service httpd start --> if it has not started yet
#  ps -ef  | grep -i tomcat

Wednesday, September 30, 2015

Linux Crontab example

## run java.jar daily

10 4 * * * /opt/my.sh  > /opt/logs/dailylog.log 2>&1


# script to run a jar file
my.sh

#! /bin/bash
echo $(date) > /opt/logs/dailylog.log
java -jar /opt/my/MyOpenSDK.jar

Tuesday, September 29, 2015

openLDAP log

OpenLDAP Log:
To get a summary on OpenLDAP Log files, openLDAP is using the Linux system log as log.
:/opt/openldap-production/var/openldap-slurp/replica (replicate log, not sys log)
config file: /opt/openldap-production/etc/config/master-sldap.conf  (loglevel 256)
syslog file: /etc/syslog.conf  

# For slapd.log
local4.* /var/log/slapd.log (log file location)
 grep "BIND dn=\"uid"  slapd.log > log.txt
 grep "BIND dn=\"uid=" slapd.log | sort -k8 -u


Friday, September 25, 2015

Java Singleton

Singleton is a POJO java class which is just having a nice name. It is used when one resource is shared within one application.

Example: write an access code in a singleton class then call it from other class

1. Singleton class

public class DirectorySingleton {
    private static DirectorySingleton authSingleton = new DirectorySingleton();
    public static  Directory dir= null;

   /* A private Constructor prevents any other   class from instantiating. */
   static{

        if (dir == null){
            try{
                 HttpTransport httpTransport = new NetHttpTransport();
                JsonFactory jsonFactory = new JacksonFactory();

                GoogleCredential credential = new GoogleCredential.Builder()
                .setClientSecrets(GmailConstants.CLIENT_ID, GmailConstants.CLIENT_SECRET)
                .setJsonFactory(jsonFactory).setTransport(httpTransport).build()
                .setRefreshToken(GmailConstants.REFRESH_TOKEN).setAccessToken(GmailConstants.ACCESS_TOKEN);

                Directory service = new Directory.Builder(httpTransport, jsonFactory, credential)
                .setApplicationName(GmailConstants.APPLICATION_NAME)
                .build();
               // System.out.println("called once");

                dir = service;
            }catch(Exception e){

            }

        }

   }
}

2, used it from other class:

    Boolean userExisted = DirectoryUtils.validateUser(DirectorySingleton.dir,
                     GmailConstants.DOMAIN_NAME, primaryGmailID);

Linux Script

[oracle@oidm-dev1 bin]$ lsb_release -i -r
Distributor ID: RedHatEnterpriseServer
Release:        6.6

Check running tasks: ps -elf | grep oracle

#netstat -an |grep 443 (to check if the port if open)
#netstat -an | egrep 'Proto|LISTEN'
#service iptables status



osearch in vi: /searchtext 

osudo su - (to work as root)
onetstat -an |grep 443 (to check if the port if open)
otail -f catalina.out (tail the content of a file)
o./file to run a local file
· show port:
onetstat -an | egrep 'Proto|LISTEN'
oservice iptables status



computer IP: nslookup computer.name.com
find file contains some text: find / -type f -name *.xml  | xargs grep -l "looking for text"

find some files: find . -name 'conf*' 


Last modified file summarized into one file:
#find *csv -mtime -10 -exec cat {} >> today.csv \;

Grep the content of a log file and sort the result, no repeat record
#grep "BIND dn=\"uid=" slapd.log | sort -k8 -u 

How do I find the most recently changed files in a set of subdirectories on Unix or Linux?

Answer 1: This will show the most recent 10 files in current directory and below.

It supports filenames with spaces. And can be slow with lots of files http://stackoverflow.com/a/7448828
sudo find . -type f -exec stat --format '%Y :%y %n' "{}" \; | sort -nr | cut -d: -f2- | head
2015-08-03 13:59:49.000000000 -0700 files/CV_Smith_1July2015.pdf
2014-12-05 09:46:33.000000000 -0800 files/CV_Smith_1Dec2014.pdf
2013-03-04 10:23:16.000000000 -0800 files/Thumbs.db
2013-03-04 10:16:57.000000000 -0800 files/CV_Smith_March2013.pdf
2013-01-07 11:44:11.000000000 -0800 files/CV_Smith_5Jan2013.pdf

Answer 2: This will show all files modified in last day, in current directory and below

find . -mtime -1 -ls
This version will just print the filenames, without the file sizes or times.
find . -mtime -1 -print




Books:
http://www.freeos.com/guides/lsst/
http://www.codecoffee.com/tipsforlinux/articles/030.html?sudo

Wednesday, September 16, 2015

Xming set up on windows


 
And then I can run
export DISPLAY=localhost:10.0 on a non putty ssh session

And then
Xclock and other X windows applications run. 


After install Xming
1)      Run “xhost +” on your desktop xming window
modify the X0.host file on windows machine 
X0.host  
localhost
oidm-dev1.csun.edu
130.166.5.152

2)      Execute “export DISPLAY=:0” on linux machine
3)      Run “xclock” on linux machine and see if you see a clock on your laptop

Will encounter following error if X0.host file not modified
[root@oidm-dev1 /]# xhost + 130.166.10.225
No protocol specified
xhost:  unable to open display "it-d73-0813.csun.edu:0.0"


At the Linux side, open all firewall, 
# service iptables save
# service iptables stop
# chkconfig iptables off