Linux exclude certain files formats eg : *.gz *.zip from a tar archive

If you want to exclude certain filetypes from the directory when creating a tar archive use the –exclude parameter for tar

tar -zcvf filename.tar.gz abc_direc/ –exclude=’*.zip’ –exclude=’*.gz’ –exclude=’*.log’ –exclude=’*.pdf’

tar -zcvf wha_clean.tar.gz public_html/ –exclude=’*.zip’ –exclude=’*.gz’ –exclude=’*.log’ –exclude=’*.pdf’ –exclude=’*.jpg’ –exclude=’*.JPG’ –exclude=’error_log’ –exclude=’*.tar’

The chosen size is not valid for the chosen file system /dev/disk2 : MacOS Mojave

Restore a bootable USB flash drive to normal on MacOS

If you are trying to format a USB disk on MacOS Mojave and get the below error

The chosen size is not valid for the chosen file system.

Go to Terminal and first check the USB device’s path

$ diskutil list
/dev/disk0 (internal):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme 500.3 GB disk0
1: EFI EFI 314.6 MB disk0s1
2: Apple_APFS Container disk1 500.0 GB disk0s2

/dev/disk1 (synthesized):
#: TYPE NAME SIZE IDENTIFIER
0: APFS Container Scheme – +500.0 GB disk1
Physical Store disk0s2
1: APFS Volume Macintosh HD 395.2 GB disk1s1
2: APFS Volume Preboot 44.9 MB disk1s2
3: APFS Volume Recovery 512.8 MB disk1s3
4: APFS Volume VM 4.3 GB disk1s4

/dev/disk2 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *8.0 GB disk2
1: 0x17 3.1 GB disk2s1
2: DOS_FAT_12 720.9 KB disk2s2

 

As you can see the external device is /dev/disk2

Zero out the disk with a simple command like below

$ diskutil zeroDisk /dev/disk2
Started erase on disk2
Finished erase on disk2

Now you can select the disk from ‘Disk Utility’ and change the filesystem to any format of your choosing.

 

Cannot uninstall ‘six’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall

Installing Mechanize gives error on MacOS Mojave For Python and Pip 2.7 This error is due to a version of ‘six’ which comes default with MacOS

Use the below command to ignore the version of six installed and install mechanize

# pip2.7 install mechanize –ignore-installed six –user

see also “https://github.com/pypa/pip/issues/3165”

Connect SQL Developer 18.3 with Oracle Autonomous Data Warehouse Cloud

Download the client credentials from your Oracle Cloud account for your Autonomous Data Warehouse Instance. Make sure you note down the username (ADMIN) & password, this will be required later during the connection process

1. Open SQL Developer

create new connection > connection type : cloud wallet

Screen Shot 2018-11-11 at 1.16.21 AM

2. Download JCE files from https://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html
Unzip the files and it will create a folder called “UnlimitedJCEPolicyJDK8” with below files

US_export_policy.jar
local_policy.jar
README.txt

3. Find path of your JDK 8 and the policy folder

On my Mac it was at : /Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk

The policy folder which contains jce files is in ../Contents/Home/jre/lib/security

cd /Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/jre/lib/security

4. Copy unlimited access jce files to the policy folder in jdk directory on your machine

sudo cp -p *.jar /Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/jre/lib/security

5. Restart SQL Developer and if everything goes well you can see the configuration file, this is the place where you will give the path for the client credentials

Screen Shot 2018-11-11 at 1.15.26 AM

Configuration file : wallet_DB201811102318.zip

Connection Name : Test Autonomous DB Warehouse

Username : ADMIN

Password : ***********

Do a test and if it is a success, you can save the connection. After you connect, you can create tables, Pl/SQL packages as you would do normally in SQL Developer

Screen Shot 2018-11-11 at 1.23.48 AM

 

 

Oracle Cloud : Introduction

Oracle has been an incumbent to the cloud space having lost a lot of ground to Amazon and Microsoft.But that hasn’t stopped them to go all guns blazing at the cloud market. Playing on it’s strength of offering Enterprise Applications in a heavily crowded SaaS space along with PaaS and IaaS offerings. Oracle has been pushing aggressively to put their Enterprise on-premise customers to the cloud, their initial offering in this space was nothing to talk about. But the game has changed in the last year with the launch of the Autonomous Data warehouse and Transaction processing cloud .

So after months of trial & error I finally decided to get an Oracle Cloud account. I was not to sure about the general availability of Oracle cloud in Australia, but lucky for me it is available for trial in Australia, though the regions it shows available does not include a Australian availability zone

Screen Shot 2018-11-11 at 12.02.01 AM.png

To get an Oracle Cloud trial account (with 400$ AUD free credit for 3o days) all you need is an email address and a credit card. The credit card is not charged but only a hold of 1$ is put on the card and returned after 3-5 business days.

Head over to https://cloud.oracle.com/home to begin your trial

Once you are done with all the formalities it sends you a temporary password to the email address used for registration. Upon first login you are asked to reset the password.

And there you are, the Oracle Cloud Dashboard page

Screen Shot 2018-11-11 at 12.07.10 AM

This is going to be series and in the next few posts i will be looking at creating an autonomous data warehouse and a transaction processing cloud database.

Send Alerts to Slack with Bash Shell Script

Slack has quickly become one of the standard messaging apps in the Enterprise. Many a companies use slack for communication amongst team members and IT departments like having slack channels for projects or critical system groups.

slack

Since most of the people who are supposed to take action on a event are in a slack channel it is sometimes better to have notifications send directly to slack for server events.

One of the requirement I had recently was to create server alerts for checking API gateways and if the webservice was found to be down, to send alert to a slack channel.

To create such event based notification to slack, first you need to create an app in slack and then a webhook to expose it to the internet. Once that is done the remaining magic is done in plain old shell scripting

1. Create an APP in Slack

a) Goto https://api.slack.com/slack-apps

b) Create an App

c) Sign-in with your workspace

2. Create the Slack App and a webhook

a) Go to incoming webhooks and Activate incoming webhooks

You can see the sample of your webhook cURLthen

b) Create  a channel in your Slack eg : testalerts and assign to step c below

c) Add new Webhook to workspacee Post To : #testalerts

d) Webhook URLS for Your Workspace

curl -X POST -H ‘Content-type: application/json’ –data ‘{“text”:”Hello, World!”}’ https://hooks.slack.com/services/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

3. Test by POST’ing data to your webhook and it should now come in your slack channel

$ curl -X POST -H ‘Content-type: application/json’ –data ‘{“text”:”Hello, World!”}’ https://hooks.slack.com/services/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

4. Write Shell Script to check a Webservice URL and check for HTTP 200 OK in the header

Shell Script

#!/bin/bash
#################################################################
# SHELL SCRIPT TO MONITOR PUBLIC URL AND REST API GATEWAY
# Created By : Shadab Mohammad
# Company : Whitehat Agency, Sydney
# Created Date : 25/10/2018
# Modified Date : 29/10/2018
#
#################################################################
## Check ASIC WebService ##
#################################################################
if curl -s –head –request GET https://abr.business.gov.au | grep “200 OK” > /dev/null; then
echo “https://abr.business.gov.au is UP”
else
echo “https://abr.business.gov.au is DOWN”
curl -X POST -H ‘Content-type: application/json’ –data ‘{“text”:”https://abr.business.gov.au is DOWN”}’ https://hooks.slack.com/services/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
fi

The above shell script checks the header for 200 OK message , if found it sends alert to the channel via the slack webhook. It can be added to crontab to check the status of the webservice every 5 minutes. If the Webservice is down it will send notification to the Slack channel.

 

IBM buys Redhat in US$34 Billion deal

In one of the largest software M&A ever, IBM has paid US$34 billion in cash to acquire the Enterprise opensource OS company Redhat. The merger was announced few hours before and has come as a shock to many a companies.

This marks a new era in IBM’s cloud push, but what would be interesting is to watch how IBM would treat Redhat’s cash cow Redhat Enterprise Linux. Will it let Redhat run as an independent entity or start tightly coupling it with IBM’s Power cpu architecture.

You can read more on the news in the link below:

https://www.businessinsider.com.au/ibm-is-reportedly-nearing-a-deal-to-acquire-redhat-the-software-company-valued-at-20-billion-2018-10?r=US&IR=Tred_hat_logo

 

Replace duplicate values only in consecutive records with NULL

— Replace duplicate values only in consecutive records with NULL [duplicate]–

SELECT
CASE
WHEN lag(tran_id) over(order by NULL) = tran_id
THEN NULL
ELSE tran_id
END tran_id,
CASE
WHEN lag(tran_name) over(order by NULL) = tran_name
THEN NULL
ELSE tran_name
END tran_name,
flag
FROM t;

TRAN_ID TRAN_N F
———- —— –
101 Lend A
B
C
D
102 Borrow E
101 Lend F
G

7 rows selected.

SELECT
CASE
WHEN lag(A.CLIENTID) over(order by NULL) = A.CLIENTID
THEN NULL
ELSE A.CLIENTID
END CLIENTID,
CASE
WHEN lag(A.QUOTEID) over(order by NULL) = A.QUOTEID
THEN NULL
ELSE A.QUOTEID
END QUOTEID,
A.CLIENT_TYPE,
B.FISCAL_YEAR
FROM creditcheck_indv A
LEFT OUTER JOIN CREDIT_FISCAL_YEARS B ON A.CLIENTID=B.CLIENTID

CLIENTID          QUOTEID          FISCAL_YEAR
——–                     ——–                   ————
12345                   2222                   10/SEP/18
14/SEP/17

ORDS Create Basic Authentication for a RESTful Web Service

ORDS Basic Authentication

mobile-security-laptop-fingerprint-730x442.jpg

1. To protect the web service, we need to create a role with an associated privilege, then map the privilege to the web service

BEGIN
ORDS.create_role(
p_role_name => ‘boomi_role’
);

COMMIT;
END;
/

— Display the role.
COLUMN name FORMAT A20

SELECT id, name
FROM user_ords_roles
WHERE name = ‘boomi_role’;

ID NAME
———- ——————–
10063 boomi_role

DECLARE
l_arr OWA.vc_arr;
BEGIN
l_arr(1) := ‘boomi_role’;

ORDS.define_privilege (
p_privilege_name => ‘boomi_priv’,
p_roles => l_arr,
p_label => ‘Vehicle Data’,
p_description => ‘Allow access to the Vehicle data.’
);

COMMIT;
END;
/

— Display the privilege.
COLUMN name FORMAT A20

SELECT id, name
FROM user_ords_privileges
WHERE name = ‘boomi_priv’;

ID NAME
———- ——————–
10064 boomi_priv

— Display the privilege-role relationship.
COLUMN privilege_name FORMAT A20
COLUMN role_name FORMAT A20

SELECT privilege_id, privilege_name, role_id, role_name
FROM user_ords_privilege_roles
WHERE role_name = ‘boomi_role’;

PRIVILEGE_ID PRIVILEGE_NAME ROLE_ID ROLE_NAME
———— ——————– ———- ——————–
10064 boomi_priv 10063 boomi_role

 

 

2. To protect the web service, we associate the privilege directly to a URL pattern.
Refer : ORDS Basic Authentication Not Working (Doc ID 2375337.1)
Full REST URL : GET : https://hostname:8443/ords/moov/v1/

BEGIN
ORDS.create_privilege_mapping(
p_privilege_name => ‘boomi_priv’,
p_pattern => ‘/v1/*’
);

COMMIT;
END;
/

— Display mapping.
COLUMN name FORMAT A20
COLUMN pattern FORMAT A20

SELECT privilege_id, name, pattern
FROM user_ords_privilege_mappings
WHERE name = ‘boomi_priv’;

PRIVILEGE_ID NAME PATTERN
———— —————————————–
10064 boomi_priv /v1/*

Once this mapping is in place, we can no longer access the web service without authentication. We haven;t defined how we should authenticate, but only that we need some authentication to access this web service

3. Create a new ORDS user called “boomi_user” with access to the “boomi_role” role.

$ cd $CATALINA_HOME/webapps/ords

$ $JAVA_HOME/bin/java -jar ords.war user boomi_user boomi_role
Enter a password for user boomi_user: *******
Confirm password for user boomi_user: ********
Sep 03, 2018 12:06:34 AM oracle.dbtools.standalone.ModifyUser execute
INFO: Created user: boomi_user in file: /u01/conf/ords/credentials

Now access the web service from a client like POSTMAN or PAW and use basic authentication with username and password which you set earlier

username : boomi_user
password: ******

 

ORDS 18.2 – The database user for the connection pool named apex_pu, is not authorized to proxy to the schema named

ORDS Version : 18.2
Oracle Version : 12cR2

Error : The database user for the connection pool named apex_pu, is not authorized to proxy to the schema named HR

Desc: The error occurs when you have published a RESTful web service from a table inside a schema. When you try to call the Webs service it gives an internal error, because the schema does not have proxy connect privilege to the ORDS public user.

Solution : Grant the username connect through privilege

SQL> alter user HR grant connect through ords_public_user;

Now try calling the REST service again and it should return the valid result set.