Bash Script Validation

Eg

#!/bin/bash

if [ $# -lt 3 ] ; then
echo “Usage: $0 username password true/false”
exit 1
fi

Validate and show if the param at least has 3 params

Waht about this ?

function printUsage {
echo "Usage: $0 "
exit 1
}

if [ $# -lt 4 ]; then
printUsage
fi

Advertisements

Exposing Simple REST Service

Exposing Simple REST Service.

Mule Studio, adding Community Edition Lib

Mule Studio by default is using

 

In order to install Community Edition following is the step:

1.  Click Help=>Install New Sofware.

2. Shoose All Available Sites

3. Click in tick box for MuleStudio Community Runtimes

4. Click Next keep continue ūüôā

 

Here is the screenshoot that might help you guys

 

 

Screenshot_1

 

 

Happy Muleeeee

Mule ESB

Imagine you are integrating one app to another app and more app is there. The integration point is hetero gen one to another application. One application provide flat file, while the other use web service, another one provide DB read  only (view) for the integration point (we called it end point).

So, to handle this kind of situation two approach can use

1. Develop application and do formatting as per integration point.

2. Use ESB to do handle this.

 

Mule is one of the open source ESB dan provide community Edition and Enterprise Edition.

Here is the sample that I made in Mule Designer to integrate .Net (REST API) endpoint with Java (cxf API).

 

Mule ESB

Using Community Edition

Audit Master Table by Trigger

Misal Nama Table yang kita mau audit adalah table M_PRICE dan kita mau mengaudit setiap ada activity Add, Update and Delete terhadadap table ini.
Kita perlu 2 table untuk mengaudit, satu untuk mencatat data2 yang diubah (tracking), satu table lagi digunakan untuk mencatat summary sudah berapa kali berubah master table tersebut.

M_PRICE ==> master table

M_PRICE_A ==> Audit table

M_PRICE_C ==> tracking berapa kali berubah

Dan berikut Triger yang bisa kita buat dengan nama M_PRICE_T

 

create or replace
TRIGGER M_PRICE_T BEFORE INSERT OR DELETE OR UPDATE ON M_PRICE FOR EACH ROW
DECLARE
l_change_num NUMBER;
BEGIN
— Increment the change_num for this table and keep the new value
UPDATE M_PRICE_C set change_num = change_num+1 returning change_num into l_change_num;

— Insert appropriate audit row(s)
IF INSERTING THEN
INSERT INTO M_PRICE_A(PRICE_ID, PRICE_NAME, change_num, aud_action, aud_timestamp) VALUES(:new.PRICE_ID, :new.PRICE_NAME, l_change_num, ‘I’, SYSDATE);
ELSIF UPDATING THEN
INSERT INTO M_PRICE_A(PRICE_ID, PRICE_NAME, change_num, aud_action, aud_timestamp) VALUES(:new.PRICE_ID, :new.PRICE_NAME, l_change_num, ‘AU’, SYSDATE);
INSERT INTO M_PRICE_A(PRICE_ID, PRICE_NAME, change_num, aud_action, aud_timestamp) VALUES(:old.PRICE_ID, : old.PRICE_NAME, l_change_num, ‘BU’, SYSDATE);
ELSE
INSERT INTO M_PRICE_A(PRICE_ID, PRICE_NAME, change_num, aud_action, aud_timestamp) VALUES(:old.PRICE_ID, : old.PRICE_NAME, l_change_num, ‘D’, SYSDATE);
END IF;
END M_PRICE_T;

In Oracle how to Check is there any table got locked?

Here is the query

SELECT a.sid,a.serial#, a.username,c.os_user_name,a.terminal,
b.object_id,substr(b.object_name,1,40) object_name
from v$session a, dba_objects b, v$locked_object c
where a.sid = c.session_id
and b.object_id = c.object_id

Deleting files older than 30 days automatically

1. create the script to find files older than 30 days and delete the files, suppose the script file name is deletefile

can use this

find  /home/mujoko/archive/  -mtime +30    -exec rm {} \;  // find files the older than 30 days in /home/mujoko/archive/  folder, make sure there is space after rm and before {}

or

find  /home/mujoko/archive/ -mtime +30 |xarsg rm // using this script its possible we face error too many parameters if the files is to many to delete

2. Login as root

3. Configure crontab by execute

crontab -e mujoko  //replace mujoko by your own username

4. Edit crontab by adding

30 1 * * * /home/mujoko/deletefile    //deletefile is the file you create at step 1

5. Save your crontab.

Walaaaa, your file within /home/mujoko/archive will be deleted when the files is older than 30 days.