Friday, July 24, 2020

Shell Scripts


Pre-requisites    : 

# Application.properties

# Utility.sh (Shell script)

# CSV file (contains users data)




Application.properties    :

Database.url = jdbc:oracle:thin:@HOSTNAME:1521/OIMDEV

OIM.DataSource = jdbc/operationsDB

OIM.url = t3://hostname:14000

OIM.context = weblogic.jndi.WLInitialContextFactory

OIM.authLoc = /home/bpr/scripts/lib/authwl.conf

Filepath = /home/bpr/scripts


Utility.sh    :

#!/bin/sh

readonly LIBRARY=/home/bpr/scripts/lib

readonly PROPERTY_FILE=/home/bpr/scripts/lib/Application.properties

export CLASSPATH=$CLASSPATH:$LIBRARY/Opencsv-2.5.jar:$LIBRARY/ojdbc6.jar:$LIBRARY/ojdl.jar:$LIBRARY/CRUDOperation.jar:$PROPERTY_FILE

export CLASSPATH=$CLASSPATH:/home/bpr/Jars/oimclient.jar:/home/bpr/Jars/spring.jar:/home/bpr/Jars/wlfullclient.jar:/home/bpr/Jars/commons-logging.jar:/home/bpr/Jars/jrf-api.jar

echo "Enter the File Path"

read filepath

java -cp $CLASSPATH com.oim.CrudOpeartion $PROPERTY_FILE $filepath


NOTE :

Fully qualified class name : com.oim.CrudOpeartion


Crud.csv    :

UserLogin,EmployeeNumber,Justification,EndDate
prasadx2,12345678,Vacation Leave, 20201024


package com.xyz.user.util;

/**
 * @author Prasad Reddy
 *
 */
public class CustomException extends Exception {

private static final long serialVersionUID = 1L;

public CustomException() {
super();
}

public CustomException(String message) {
super(message);
}

public CustomException(Throwable cause) {
super(cause);
}

}

--------------------------------***************--------------------------------

package com.xyz.user.util;

import java.io.FileInputStream;
import java.sql.Connection;
import java.util.Hashtable;
import java.util.Properties;
import javax.naming.Context;
import javax.sql.DataSource;

/**
 * @author Prasad Reddy
 *
 */
public class Util {

public Properties loadProperty(String name) throws Exception {
Properties pros = new Properties();
try {
pros.load(new FileInputStream(name));

} catch (Exception e) {
System.out.println("Excetion is : " + e.getMessage());
throw new Exception("Exception while loading Properties file : " + e.getStackTrace());
}
return pros;
}

public Connection getConnection(Properties properties) {
Connection connection = null;
DataSource ds = null;
try {
Hashtable<Object, Object> env = new Hashtable<Object, Object>();
env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, properties.getProperty("OIM.context"));
env.put("OIMClient.JAVA_NAMING_PROVIDER_URL", properties.getProperty("OIM.url"));

Context context = new InitialContext(env);
ds = (DataSource) context.lookup("OIM.DataSource");
System.out.println("Successfully looked up OIM datasource : ");
if (ds != null) {
connection = ds.getConnection();
System.out.println("Database connection is successful :");
}

} catch (Exception e) {
System.out.println("Error in getting connection" + e.getMessage());
}
return connection;

}
}


-------------------------------------*******************---------------------------------





No comments:

Post a Comment

Fetch Members from Workgroup

  import java.util.ArrayList;   import java.util.Iterator;   import java.util.List;   import sailpoint.api.ObjectUtil;   import sailpoint.ob...